The example bellows compiles, but the output is rather strange :
#include
#include
struct A
{
int a;
char b;
bo
I can't seem to find anything in the standard that indicates why this would happen (most possibly my fault here) -- this does include the reference provided by 7vies, which is not in itself very helpful. It is definitely undefined behavior, but I can't explain the specific behavior that is observed by the OP.
As a practical matter, I 'm very surprised that the output is
true
true
Using VS2010, the output is the much more easy to explain:
false
false
In this latter case, what happens is:
true are implemented by the compiler as tests for equality to 0x01, and since 0xff != 0x01 the result is false.false, only the value compared with is now 0x00.I can't think of any implementation detail that would cause false to compared equal to the value 0xff when interpreted as bool. Anyone have any ideas about that?