Assignment in test: OK?

Tim Bomgardner bomgard at iuvax.cs.indiana.edu
Wed Sep 12 02:38:42 AEST 1990


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 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)

I agree, 'if(7 == x)' is ugly.  It makes me stop, back up, and reread.  My 
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.



More information about the Comp.lang.c mailing list