difference between c++; and ++c;

Hascall John Paul john at iastate.edu
Tue Apr 9 05:06:29 AEST 1991


hnridder at cs.ruu.nl (Ernst de Ridder) asks why:
}	   ++c;
}instead of
}	   c++;

   Consider for a moment (yes, these are not equivalent):

           x = ++c;       vs       x == c++;

These can be "compiled" as:

                                   temp_001 <-- c;
           c <-- c + 1;            c <-- c + 1;
           x <-- c;                x <-- temp_001;

(now throw away the "x=" part (last "instruction").

So, "++c" is ``cleaner'' in some pedantic sense[1], and I suppose a
sufficiently lacking compiler might actually produce slower code
for "c++;" than for "++c;".

John

[1] I am one of those "guilty" of using "++c;"
--
John Hascall                        An ill-chosen word is the fool's messenger.
Project Vincent
Iowa State University Computation Center                       john at iastate.edu
Ames, IA  50011                                                  (515) 294-9551



More information about the Comp.lang.c mailing list