C programming style

Ken Arnold%CGL arnold at ucsfcgl.UUCP
Fri Jul 19 08:23:03 AEST 1985


In article <186 at drivax.UUCP> braun at drivax.UUCP (Karl Braun) writes:
>The comment regarding the effeciency of the
>produced code is probably applicable to most compilers, but academically, any
>reasonable optimizer should optimize 'i = i + 1' to equivelant code.  

(I have extracted this out of an article I otherwise agreed with
completely, because this is not true, as will be elucidated below).

This is quite true for such simple expressions as
	i = i + 1;
but not true at all for such things as
	a[f()] = a[f()] + 1;
which cannot be reduced to
	a[f()]++;
Which is another reason why this can't be done.

Another thing which ++ saves is typos.  If you use
	i = i + 1;
you must retype "i".  This is fine when "i" is simple, but if it is
a complex variable expression, you could get two legal expressions which
are different instead of the same, and then not get the same effect
(not to mention the efficiency).

All in all, if "increment(i)" is more clear than "i++", you don't know
C.  Since ++ means "increment", nothing could be clearer.  Or would you
prefer "and", "or", "plus", "minus", etc.?  Urg.

		Ken Arnold



More information about the Comp.lang.c mailing list