[Tutor] Re: Why x+=y instead of x=x+y?

lumbricus@gmx.net lumbricus@gmx.net
Tue, 6 Aug 2002 06:45:26 +0200 (MEST)


Hello!

> > > 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.

I just asked the guys at comp.lang.c
See Message-ID: <ain78l$r4j$1@bob.news.rcn.net> 

> Interesting, I must go do some experimentation when I get 
> into work tomorrow. It could be a change in the latest 
> ANSI standard but I hope not, an awful lot of code relies 
> on those differences!

Bad luck :-(

> I'm particularly alarmed at i = i + 1 having the same 
> behaviour since if i is a 'register' variable then that 
> potentially changes the whole CPU semantics! 
> 
> > But they _are_ equivalent IIRC. 
> > But I don't have a copy of the
> > Standard at hand to look it up *wink*.
> 
> The last time I used raw C (as opposed to C++) was 
> pre ANSI compilers(~1993/4), so the standard may 
> have changed the rules. I'll check tomorrow...

The standard never says _how_ to implement
something. This is AKA the "as if rule"(sp?) AFAIK.
 
> > Now I am really courious what compilers You use.
> 
> The Sun Workbench, An HP EPROM programmer and the VAX VMS 
> standard C compiler. Also occasionally the PSOS and OS/9 
> compilers. We also used gcc(v2.something) for one job 
> cross compiling to a Texas Instruments chip (can't recall 
> which!) so I'm interested to see gcc in your list.
> 
> Alan G
 
HTH, HAND
and Greetings, J"o!

-- 


-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net