Messages in this thread | | | Date | Sat, 26 Jan 2002 10:48:51 -0500 | From | Ben Bridgwater <> | Subject | Re: RFC: booleans and the kernel |
| |
Rick Stevens wrote:
> 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.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |