This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Change in order of evaluation in 4.0.2


Hi,
I've had a report from a friend that a program that I had written
was crashing running a basic test which ran fine on my machine.
He noted that he was using gcc 4.0.1, whereas I am running 3.4.1
(Mandrake 10.1) so I suspected a compiler bug might be the case.
I use the gcc compiler a lot, but don't know enough to be
able to install the new relase as a 'test' version in parallel
with 3.4.1 so I was reluctant to download/install 4.0.1 to test
this. After a couple of remote gdb runs, I still hadn't tracked 
down the problem, so I asked him to e-mail me a statically linked
executable. Running this under gdb quickly established the
cause of the problem - it was not a compiler bug, but a significant
change in the order of evaluation of expressions. The statement
in question was basically:

	a = b - c();

but the routine c() has the side effect of changing b. I had made
the assumption that routines are always evaluated before a 'simple'
operand would be loaded, which would be the case if I had written
the compiler. However, it was clear that under 4.0.1, the value
of 'b' was being loaded into a register before 'c' was invoked
and the result was therefore different. 

I appreciate that this is quite valid according to the ANSI C 
standard and the team are within their rights to change this,
but I am curious to know the reasoning behind the change which
seems to me to make the object code less optimal.

Bill
-- 
+---------------------------------------+
| Bill Purvis, Amateur Mathematician    |
|  email: bil@beeb.net                  |
|  http://bil.members.beeb.net          |
+---------------------------------------+


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]