C Style (Was Re: == vs =)

Tom Neff tneff at atpal.UUCP
Thu Apr 14 02:32:26 AEST 1988


In article <1982 at ubc-cs.UUCP> pajari at grads.cs.ubc.ca (George Pajari) writes:
>In article <130 at obie.UUCP> wes at obie.UUCP (Barnacle Wes) writes:
>>    if (status = *statreg) {
>
>What is wrong with:
>
>	if ((status = *statreg) != NULL)...

For what it's worth, the latter is the preferred formulation as recommended 
by Harbison&Steele (2nd ed.) and Gimpel's PC-LINT, among others.  Certain
grizzled veterans may crave the older, less wordy, more "clever" formulation,
but the explicit comparison is easier to read and less likely to be confused
for something else.  If you get into the habit of never writing if(variable),
you don't tend to have =/== accidents, in my experience.  Also, both MSC
and PC-LINT are nice and flag the former usage above as being possibly a
typo.
-- 

Tom Neff 



More information about the Comp.lang.c mailing list