[Tutor] Re: Why x+=y instead of x=x+y?
lumbricus@gmx.net
lumbricus@gmx.net
Sat, 27 Jul 2002 17:30:41 +0200 (MEST)
> > > > I think it is also related to the complexity of the compiler. I
> > > > expect that any modern compiler will turn "x+=1" into INC X.
> > >
> > > If optimisation is turned off I sincerely hope it doesn't!
> >
> > Why not?
>
> Because if I'm writing a time critical program and I have
> a loop that's running just slightly too fast with an x++
> in it I expect to be able to slow the loop down by changing
> x++ to x+=1
I cant get any of my compilers (Digital UNIX Compiler Driver 3.11
and gcc) to compile (with -O0 to turn off all optimization)
i=i+1, i+=i and i++ differently.
One (on x86) always codes "incl " the other one
(on alpha) always says "addl $1, 1, $1".
> If the compiler treats those two as equivalent then the
But they _are_ equivalent IIRC.
But I don't have a copy of the
Standard at hand to look it up *wink*.
> loop won't change. That's the kind of premature optimisation
> that I don't want. (It also affects debugging of complex
> code too, if the assembler is the same for x++ and x+=1
> I'm going to have some strange results when running the
> assembler debugger.)
Now I am really courious what compilers You use.
> Alan g.
Greetings, J"o!
--
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net