difference between c++; and ++c;

Joseph Schwartz xor at aix01.aix.rpi.edu
Tue Apr 9 03:42:32 AEST 1991


In article <1991Apr08.161444.10025 at cs.ruu.nl> hnridder at cs.ruu.nl (Ernst de Ridder) writes:
>I once read (I'm not sure where, but I believe it was in the C++
>programming language) that some C-programmers argue that ++c is neater
>than c++.  (In situations where the side-effect doesn't matter).  So
>they write (just as an illustration)
>	while ( c < 100)
>	   ++c;
>instead of
>	while ( c < 100)
>	   c++;
>
>Why should one of these forms be preferred over the other in such a situation,
>apart from personal preferences?
 
Well, in the above example, it doesn't really matter whether you use c++ or
++c.  However, say you had this instead:
 
     while (*pFoo < 100)
       ++*pFoo;
 
I prefer to preincrement, because postincrement would require some parens:
 
     while (*pFoo < 100)
       (*pFoo)++;
 
So in general, I will preincrement wherever I have a choice, to avoid making
the mistake of leaving out the above parentheses.

-- 
Joe Schwartz
Internet: xor at mts.rpi.edu
Bitnet: userez3n at rpitsmts



More information about the Comp.lang.c mailing list