https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67433
xuejuncao <xuejuncao at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|?: expresion returns |?: expression returns |unexpected value when |unexpected value when |condition is a bool |condition is a bool |variable and it's value |variable which memory is |above 1 |not true/false --- Comment #1 from xuejuncao <xuejuncao at gmail dot com> --- #include <stdio.h> #include <stdbool.h> #include <string.h> int main() { union u { bool b; char c; } u; memset((void *)&u, -1, sizeof(u)); bool b = (u.b ? 1 : 0); int i = (u.b ? 1 : 0); int j = (u.b ? 1 : 2); printf("b = %d, i = %d, j = %d\n", b, i, j); return 0; } without optimisation, the output is: b = 1, i = 255, j = 1 with -O2, is: b = 255, i = 255, j = 1