[Tutor] Re: Why x+=y instead of x=x+y?
alan.gauld@bt.com
alan.gauld@bt.com
Wed, 24 Jul 2002 17:23:48 +0100
> > > 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
If the compiler treats those two as equivalent then the
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.)
Alan g.