1
0
mirror of https://gitlab.com/80486DX2-66/gists synced 2024-11-08 08:54:34 +05:30

bool-operations.c: compare to unsigned char

This commit is contained in:
Intel A80486DX2-66 2024-06-25 23:14:34 +03:00
parent 105deedfac
commit cbaf939777
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -12,37 +12,38 @@
#include <stdlib.h>
#define BOOL_TO_STR(x) ((x) ? "true" : "false")
#define SHOW_BOOL printf("boolean = %s\t(0x%" PRIxMAX ")\n", \
BOOL_TO_STR(boolean), \
(uintmax_t) boolean)
#define SHOW_BOOL_INT printf("boolean = %s\t(0x%d) | integer = %s\t(0x%d)\n", \
BOOL_TO_STR(boolean), (int) boolean, \
BOOL_TO_STR(integer), (int) integer)
int main(void) {
bool boolean = false;
unsigned char integer = (unsigned char) boolean;
printf("Loop:\n");
for (uint8_t i = 0; i < 3; i++) {
SHOW_BOOL;
boolean++;
SHOW_BOOL_INT;
boolean++; integer++;
}
printf("\n* 2:\n");
boolean *= 2;
SHOW_BOOL;
boolean *= 2; integer *= 2;
SHOW_BOOL_INT;
printf("\n<< 1:\n");
boolean <<= 1;
SHOW_BOOL;
boolean <<= 1; integer <<= 1;
SHOW_BOOL_INT;
printf("\n/ 2:\n");
boolean /= 2;
SHOW_BOOL;
boolean /= 2; integer /= 2;
SHOW_BOOL_INT;
printf("\n^ 0x10:\n");
boolean ^= 0x10;
SHOW_BOOL;
boolean ^= 0x10; integer ^= 0x10;
SHOW_BOOL_INT;
printf("\n>> 1:\n");
boolean >>= 1;
SHOW_BOOL;
boolean >>= 1; integer >>= 1;
SHOW_BOOL_INT;
return EXIT_SUCCESS;
}