Using `=' in a conditional (was Re: Funny mistake)

Richard Flamsholt S0rensen richard at iesd.auc.dk
Mon Mar 18 22:57:57 AEST 1991


>>>>> On 17 Mar 91 19:26:22 GMT, bevan at cs.man.ac.uk (Stephen J Bevan) said:
Stephen> For what its worth, I haven't been programming in C that long (3 - 4
Stephen> years), but I can't actually remember using a `=' when I meant `=='.

  The keyboard on Sun's SparcStations are quite slow; I've often
writen stuf containing only one letter (oops, mised that one ;-) where
it should have been a double letter and that's bit me once or twice
with the == versus = .

  Just my $0.02: using "if (x)" signals, that we're testing the
boolean value of x rather than testing whether x != 0. The reason for
using "if (x != 0)" is exactly the same reason why you write NULL or
'\0' instead of plain 0 always; you want your code to syntactically
signal your intensions.

--
/Richard Flamsholt
richard at iesd.auc.dk



More information about the Comp.lang.c mailing list