C Style (Was Re: == vs =)
James E. Prior
jep at oink.UUCP
Thu Apr 21 13:32:25 AEST 1988
In article <2823 at mmintl.UUCP> franka at mmintl.UUCP (Frank Adams) writes:
>In article <126 at atpal.UUCP> tneff at atpal.UUCP (Tom Neff) writes:
>>If you get into the habit of never writing if(variable),
>>you don't tend to have =/== accidents, in my experience.
>
>I wouldn't say "never write if(variable)"; rather "only write if(variable)
>if variable is Boolean". In my opinion, things like if(variable==TRUE) are
>abominations.
Amen!, and I'll go one further
if (var==TRUE)
is not only abominable, it can be dangerous. var==TRUE tends to presume
that the only valid values of var are FALSE and TRUE. 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 var=isalpha(c). The
isxxxxx(c) functions are often defined as macros like:
#define isxxxxxx(c) (attribute_array[c] & MASK_XXXX)
Each element of the array consists of a bunch of bit attributes. The
MASK_XXXX selects the attributes of interest, often yeilding true but
non-one (non-TRUE) values.
--
Jim Prior {ihnp4|osu-cis}!n8emr!oink!jep jep at oink.UUCP
Pointers are my friend.
More information about the Comp.lang.c
mailing list