== vs =
Andrew Scott
andrew at teletron.UUCP
Tue Jan 26 08:31:32 AEST 1988
In article <3208 at bunker.UUCP>, garys at bunker.UUCP (Gary M. Samuelson) writes:
> When I see "if (x = fn())", I know what it means, but sometimes I
> am not sure whether the author meant "if (x = fn())" or
> "if (x == fn())". I spend a lot of time trying to figure out
> what other programmers meant, even after I figure out what
> they wrote. "if( (x = fn()) != 0 )" is longer, but it is
> totally unambiguous to both the author and the (human) reader.
Not only is the "if ((x = fn()) != 0)" form unambiguous to the human reader,
it generates *identical* code as the "if (x = fn())" form does (at least on
the compiler I use). It makes a lot sense to make your intentions as a
programmer clear to other (future) programmers during the maintenance phase
of the software's life cycle, as Gary mentioned in his posting. There is no
point in using the shorthand form, unless laziness is a virtue.
Andrew Scott
--
$ make sense
Make: Don't know how to make sense. Stop.
More information about the Comp.lang.c
mailing list