Xref: utzoo comp.lang.c:38080 comp.std.c:4639 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!sun!amdcad!dvorak.amd.com!proton!tim From: tim@proton.amd.com (Tim Olson) Newsgroups: comp.lang.c,comp.std.c Subject: Re: difference between c++; and ++c; Message-ID: <1991Apr9.152139.15535@dvorak.amd.com> Date: 9 Apr 91 15:21:39 GMT References: <1991Apr08.161444.10025@cs.ruu.nl> Sender: usenet@dvorak.amd.com (Usenet News) Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Austin, TX Lines: 29 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, it mainly *is* personal preference. A reasonable compiler should generate the same code sequence for either expression. The reason many prefer the prefix operator rather than the postfix operator is that postfix operations are somewhat special -- the resultant value is that of the lvalue *before* the side-effect operation, rather than the result of the operation. Because of this difference, many use the postfix operators only when this action is required. -- -- Tim Olson Advanced Micro Devices (tim@amd.com)