Hello.
Sparing you the details of how I have come across this issue I am just going to paste an example which I simply do not get (although it's probably easy to explain - knowing my luck it has something to do with undefined behaviour
Code:
#include <stdio.h>
#include <stdbool.h>
int main(void)
{
bool b;
if (b)
printf("%d: True\n", b);
else
printf("%d: False\n", b);
if (!b)
printf("%d: False\n", b);
else
printf("%d: True\n", b);
return 0;
}
Running the program results in:
Code:
assiduus@ubuntu:~$ ./a.out
183: True
183: False
When I manually assign this random value to b, 1 is stored instead, which I understand is a normal behaviour when you try to store a nonzero value into b. The result is what you would expect:
Code:
assiduus@ubuntu:~$ ./a.out
1: True
1: True
How come the same thing does not happen during the first (b uninitialized) run? And how is it that 183 is true or false depending on how you form the "question"?
Cheers,