Here is my problem code:
#include "stdio.h"
int main()
{
char a = -1;
unsigned char b = 255;
unsigned char c = 0;
if((~a) == c)
printf("OK 1");
else
printf("bad 1");
printf("\n");
if((~b) == c)
printf("OK 2");
else
printf("bad 2");
printf("\n");
}
I expected this to print:
OK 1
OK 2
But, I get OK 1 and bad 2!
If unsigned char b
is 255 (11111111), then ~b should be 00000000. Why does it not equal c?
I work on Linux SUSE, using gcc.