Assignment in test: OK?
Rick Schubert
rns at se-sd.SanDiego.NCR.COM
Tue Sep 11 05:38:04 AEST 1990
In <1990Sep7.042759.3804 at ux1.cso.uiuc.edu> gordon at osiris.cso.uiuc.edu (John Gordon) writes:
> One way to avoid the =/== pitfall is to write your code like this:
> if(7 == x) rather than if(x == 7).
> If you write it the first way, and accidentally write = instead of ==,
> you will be trying to assign a value to a constant (!!) and will get
> an error.
I have seen this suggestion in this newsgroup quite a few times in the past
and I always wonder:
If you remember to put the constant on the left, won't you also remember
to use `==' rather than `='?
[Personally, I think `if(7 == x) is ugly.]
-- Rick Schubert (rns at se-sd.sandiego.NCR.COM)
More information about the Comp.lang.c
mailing list