On Thu, Jul 28, 2011 at 8:33 AM, Gene Buckle <ge...@deltasoft.com> wrote: > On Thu, 28 Jul 2011, Stefan Seifert wrote: > >> On Thursday 28 July 2011 01:00:10 Hal V. Engel wrote: >> >>> But there is one minor and very common issue with the code that should be >>> fixed. In the for loop >>> >>> for (..; ..; j++) >>> >>> should be >>> >>> for (..; ..; ++j) >>> >>> if you use j++ the compiler has to make a copy of j with each iteration of >>> the loop but if you use ++j it does not have to make a copy. This will >>> make the loop more efficient although only by a small amount. >> >> Are you sure about that? I just tried it with a little example and at least >> gcc compiles both variants to the exact same assembly code. Tried it with and >> without -O2. >> > That would freak me out. Doesn't "++j" mean "increment j, then test" > whereas "j++" means "test j, then increment"? No, in both cases the test is done before the increment. The difference between these cases is that in the post-increment case the initial value of the variable must be saved and returned as the value of the operation. In a typical for-loop that value won't be used, so in simple cases -- such as just incrementing an index or pointer -- the compiler might very well generate the same code. The difference is seen when the variable is an iterator with hairy overloaded functions for the increment operations.
Tim > > g. > > -- > Proud owner of F-15C 80-0007 > http://www.f15sim.com - The only one of its kind. > http://www.simpits.org/geneb - The Me-109F/X Project > Some people collect things for a hobby. Geeks collect hobbies. > > ScarletDME - The red hot Data Management Environment > A Multi-Value database for the masses, not the classes. > http://www.scarletdme.org - Get it _today_! > > Political correctness is a doctrine, fostered by a delusional, illogical > minority, and rabidly promoted by an unscrupulous mainstream media, which > holds forth the proposition that it is entirely possible to pick up a turd > by the clean end. > > ------------------------------------------------------------------------------ > Got Input? Slashdot Needs You. > Take our quick survey online. Come on, we don't ask for help often. > Plus, you'll get a chance to win $100 to spend on ThinkGeek. > http://p.sf.net/sfu/slashdot-survey > _______________________________________________ > Flightgear-devel mailing list > Flightgear-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/flightgear-devel > ------------------------------------------------------------------------------ Got Input? Slashdot Needs You. Take our quick survey online. Come on, we don't ask for help often. Plus, you'll get a chance to win $100 to spend on ThinkGeek. http://p.sf.net/sfu/slashdot-survey _______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel