From cbaf93977759ad9f32b9d8662584c4fc7040584a Mon Sep 17 00:00:00 2001 From: Intel A80486DX2-66 Date: Tue, 25 Jun 2024 23:14:34 +0300 Subject: [PATCH] bool-operations.c: compare to `unsigned char` --- c-programming/experiments/bool-operations.c | 31 +++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/c-programming/experiments/bool-operations.c b/c-programming/experiments/bool-operations.c index 1777f8d..a91093c 100644 --- a/c-programming/experiments/bool-operations.c +++ b/c-programming/experiments/bool-operations.c @@ -12,37 +12,38 @@ #include #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; }