C programming style

Walter Bright bright at dataio.UUCP
Mon Jul 22 19:51:11 AEST 1985


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

Most Pascal and Fortran compilers will replace i=i+1 with i+=1 internally.
C compilers, however, usually don't bother because the i+=1 and ++i forms
are available, and the assumption is that they would have been used. These
comments also apply to all the op= forms in C.

Some C compiler trivia:
Since (i+=1) is exactly equivalent to (++i), most C compilers immediately
translate (++i) into (i+=1), and internally use the second one from then
on. Also, (i++) is usually internally translated to (i+=1) if the result
of the expression is not used. These kinds of conversions make life
easier for the code generator.



More information about the Comp.lang.c mailing list