Xref: utzoo comp.lang.c:38046 comp.std.c:4632 Newsgroups: comp.lang.c,comp.std.c Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!xor From: xor@aix01.aix.rpi.edu (Joseph Schwartz) Subject: Re: difference between c++; and ++c; Message-ID: Keywords: pre post increment decrement grammar style Nntp-Posting-Host: aix01srv.aix.rpi.edu Organization: Rensselaer Polytechnic Institute, Troy NY References: <1991Apr08.161444.10025@cs.ruu.nl> Date: 8 Apr 91 17:42:32 GMT Lines: 32 In article <1991Apr08.161444.10025@cs.ruu.nl> hnridder@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@mts.rpi.edu Bitnet: userez3n@rpitsmts