This code is not behaving as expected. It simply tries to set bit 31 in an unsigned long int.
int main() {
printf("sizeof(unsigned long int) is %ld bytes\n", sizeof(unsigned long int));
unsigned long int v = 1 << 30;
printf("v is (%lx)\n", v);
v = 1 << 31;
printf("v is (%lx)\n", v);
}
Here is the output:
sizeof(unsigned long int) is 8 bytes
v is (40000000)
v is (ffffffff80000000)
Can anyone explain this? Maybe a problem with the printf formatting?