Equality vs Assignment

Brett Galloway brett at wjvax.UUCP
Fri Sep 26 02:55:59 AEST 1986


In article <270 at myrias.UUCP> cg at myrias.UUCP (Chris Gray) writes:
>The proper place for this check is of course as a warning issued by the C
>compiler. It's not all that hard - it took me about 30 lines of code in the
>compiler (ANSI draft based) that I've done. It's a check I felt was quite
>important, since I've been bitten by it too many times (I program in other
>languages besides C, where '=' IS a comparison).

I disagree; the proper place for this check is NOT as a warning issued by
the compiler.  "if(var=value)" is a perfectly valid, supported, and documented
construction, endorsed by K & R et al.  The fact that it is misleading is
an artifact of the ambiguity of the meaning of "equal" and "=".  In any
event, it is a well-defined and supported feature of the language.  It is
ridiculous for the compiler to bark on the expression (var=value) when it
happens to fall into the context of a simple if().

The proper place for this check is within lint, whose purpose is to

	... detect features of ... [C programs] ... which are likely
	to be bugs, or non-portable, or wasteful.

				- lint(1), from 4.2 BSD manual

Further, it should be a special test by lint, invoked by a special argument,
so that those of us who like to use lint don't have to listen to the
warning forever.

-- 
-------------
Brett Galloway
{pesnta,twg,ios,qubix,turtlevax,tymix,vecpyr,certes,isi}!wjvax!brett



More information about the Comp.lang.c mailing list