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]

Re: bug in Intel V7 Linux compiler?


>- I get wrong results when compiling
>
>	double relval[n] ;
>
>	cadd: relval[gjj+1]+=3Drelval[gjj++] ;
>
>with the Intel/Linux compiler, using
>
>	icc -c -march=3Dpentium4 -O2 adder2.c

>This is different.  The gcc compiler produces correct results in my
>(much larger) application, and the Intel compiler does not.  Am I
>doing something wrong, or is this a compiler bug?

If you post-increment gjj in one part of an expression and then use it
in another, then the results are "implementation-defined", which is to
say that the compiler is free to choose where to apply the side effect
of the post-increment, and in your example you are relying on a
particular behavior.

Change the code to:

	double relval[n] ;
	cadd: relval[gjj+1]+=relval[gjj];
	gjj++;

which makes it is explicit where the post-increment of gjj takes place.

-- 
Peter Barada
peter@baradas.org


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