condition convention 'if (10 == j)...' :-)

Arthur David Olson ado at elsie.UUCP
Wed May 8 03:15:46 AEST 1985

> To prevent silly mistakes like 
> 	if (j = 10)
> I usually write
> 	if (10 == j)
> By putting the constant first, I ensure that the compiler will catch the 
> typo.

Do remember, however, this quote from "A Tour Through the Portable C Compiler":
". . .in cases where a relational operation is being done, and one operand is a
constant, the operands are permuted, and the operator altered, if necessary, to
put the constant on the right."

This means that it will take longer to compile expressions of the form
"(10 == j)" than it will to compile expressions of the form "(j == 10)".  :-)
	UUCP: ..decvax!seismo!elsie!ado    ARPA: elsie!ado at seismo.ARPA
	DEC, VAX and Elsie are Digital Equipment and Borden trademarks

More information about the Comp.lang.c mailing list