C Style

Karl Heuer karl at haddock.ISC.COM
Sat Apr 23 02:32:25 AEST 1988


In article <255 at oink.UUCP> jep at oink.UUCP (James E. Prior) writes:
>In article <2823 at mmintl.UUCP> franka at mmintl.UUCP (Frank Adams) writes:
>>In my opinion, things like if(variable==TRUE) are abominations.
>
>[It] is not only abominable, it can be dangerous.  var==TRUE tends to presume
>that the only valid values of var are FALSE and TRUE.

If this isn't the case, it shouldn't have been declared boolean.  My coding
style is as if `bool' were a true boolean type, and as if assigning anything
other than `YES' or `NO' (yeah, I follow Kernighan, not Wirth) would produce
undefined results.

>There are times when a var can very intentionally have a non-zero (true)
>value other than TRUE (1).  The classic kind of case of this is [isalpha].

Then isalpha() is not a boolean, in my book.  I'm not convinced there's any
good reason for this; it would be trivial to rewrite the function to return a
true boolean.  In most instances this would have zero run-time cost.

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list