Assignment in test: OK?
D'Arcy J.M. Cain
darcy at druid.uucp
Fri Sep 14 23:56:55 AEST 1990
In article <57945 at iuvax.cs.indiana.edu> bomgard at iuvax.cs.indiana.edu (Tim Bomgardner) writes:
>In article <3836 at se-sd.SanDiego.NCR.COM> rns at se-sd.SanDiego.NCR.COM (Rick Schubert) writes:
>}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 remember to put the constant on the left, won't you also remember
>}to use `==' rather than `='?
>conditionals all look like Fortran: 'if (x EQ 7 OR y LT 3)'. Guess you can
>tell where *I* grew up. Haven't had a problem in years, except once from
>someone who was reusing some of my code.
Which is the problem with that sort of code. You can't give C code disguised
as FORTRAN to a C programmer and expect them to be comfortable with it. I
like to do the following;
if ((x = 7) != 0)
It makes the intention perfectly obvious to any other C programmer and most
compilers will optimize it anyway. The Borland compiler has settings that
flag the 'if (x = 7)' construct as a warning and I use this on the DOS side.
It has caught a few typos for me.
--
D'Arcy J.M. Cain (darcy at druid) |
D'Arcy Cain Consulting | MS-DOS: The Andrew Dice Clay
West Hill, Ontario, Canada | of operating systems.
+ 416 281 6094 |
More information about the Comp.lang.c
mailing list