RFC: booleans and the kernel
Quoted 2 lines · Rick Stevens
Granted. "if (x)" is true if "x" is non-zero, regardless of type and shoudn't even generate a warning if "x" is scalar.
Surely the major point of using the compiler's _Bool would be for type safety - if you only want readability then you may as well just use:
enum bool {true = 1, false = 0};
Now since C has historically utilized integer expressions for conditionals (with 0, !0 truth semantics), so it would be obnoxious to *unconditionally* make if (x) where x is non _Bool generate warnings, but IMO the whole point of using _Bool would be to then choose to turn on warnings for non _Bool conditionals, and to suppress warnings one would then need to be explicit about intentions by writing code such as:
if ((_Bool) (x = y)) ;
and hopefully if one accidently wrote:
if ((_Bool) x = y) ; /* int x, y */
then the compiler would warn that you probably didn't really mean that, since it means:
if ((_Bool) (x = (int) (_Bool) y)) ;
Which would have converted your y to _Bool (0/1) before assigning it to x.
Ben
P.S. I'm not on the list - please CC any response to me if you want a reply.