== vs =

Karl Heuer karl at haddock.ISC.COM
Sat Feb 20 03:53:47 AEST 1988


In article <909 at micomvax.UUCP> ray at micomvax.UUCP (Ray Dunn) writes:
>To others who suggest defining "EQUALS" etc for "==".  This is not a
>solution.  The problem is not with the use of "==", the problem is with the
>use of "=".  The solution *has* to involve the "=" operator.

If you don't mind the verbosity, you could define "ASSIGN" for "=".

>It unfortunately cannot be solved without breaking existing code - although
>only to the extent that syntax errors would be given on existing code by
>"new" compilers.

Well, it doesn't need to be an outright error -- as I mentioned previously, a
warning would do it.

>The "best" solution suggested so far was to disallow "=" in the context of
>the conditional expression of an if statement, and substitute some other
>operator, say ":=" (but not necessarily).

It's not necessary to create a new operator.  If "=" is disallowed in a
boolean context, you can write "if ((x = y) != 0)" to get the same effect.
It also makes the code more understandable, if you explicitly compare against
whichever of { 0, '\0', 0.0, NULL } is appropriate.

Btw, the correct spelling is "ANSI", not "ANSII".

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