The following questions (and answers) indicate that a bool's value when converted to int will be 0 or 1.
My question is whether the compiler can represent the value as something else internally (up to the conversion). I vaguely recalling the MSVC debugger show the numeric value of the byte representing the bool if it isn't 0 or 1, and I seem to recall seeing 255 sometimes (0xFF).
Said differently, could the following code return something other than 0 or 1?
int boolval(bool z) {
return *(unsigned char *)&z;
}
I am currently working with a binary format that uses bool
's in the structure and am seeing 255's instead of 0's and 1's.
EDIT: I just found an almost identical questions a moment ago so I am linking it here for more information. How is a bool represented in memory? Thanks for the answers.