This is the mail archive of the gcc-help@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: gcc 4.2.2: unexpected difference in behavior between -O0 and -Ox for x = 1, 2, 3


On 5/3/08, Benj FitzPatrick <benjfitz@yahoo.com> wrote:
> I forgot to include
>
>  return(integral);
>
>  My question is why does the buggy code give the
>  correct answer with no optimizations, but an incorrect
>  answer with optimizations turned on?

Because by chance, without optimisation, your "integral" variable
happens to be stored (or a copy of its value happens to be left) in
the same register or stack location as the default place for function
call results.  I would guess it's the first item on the stack while
the function is alive and the first item after the top of the stack
when it return.

   M


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