This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: gcc 4.2.2: unexpected difference in behavior between -O0 and -Ox for x = 1, 2, 3
- From: "Martin Guy" <martinwguy at yahoo dot it>
- To: "Benj FitzPatrick" <benjfitz at yahoo dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Sat, 3 May 2008 09:53:48 +0100
- Subject: Re: gcc 4.2.2: unexpected difference in behavior between -O0 and -Ox for x = 1, 2, 3
- References: <778665.77620.qm@web37902.mail.mud.yahoo.com>
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