Weird results for conditional operator with GCC and bool pointers
问题 In the following code, I memset() a stdbool.h bool variable to value 123 . (Perhaps this is undefined behaviour?) Then I pass a pointer to this variable to a victim function, which tries to protect against unexpected values using a conditional operation. However, GCC for some reason seems to remove the conditional operation altogether. #include <stdio.h> #include <stdbool.h> #include <string.h> void victim(bool* foo) { int bar = *foo ? 1 : 0; printf("%d\n", bar); } int main() { bool x; bool