http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50695
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #10 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-12
11:35:19 UTC ---
(In reply to comment #9)
> One further note, with stdio.h, string.h and using strtod, I get the correct
> answer suggested by Andreas Schwab:
> Bug!!0.000000E+00
>
> If I put stdio.h, string.h, and stdlib.h, I get
> Nobug
>
> Something doesn't make sense.
It makes perfect sense. Without a prototype for strtof (which is provided
by stdlib.h) strtof get's implicitely declares as
int strtof();
which means the return value is expected to be an integer returned in %eax
which then gets converted to floating-point. But in reality strtof is
float strtof(const char *nptr, char **endptr);
and the return value is returned in %xmm0 and only a widening from float
to double would be necessary.
Thus, your program is invalid and it will just use garbage that happens
to be present in %eax.
GCC tells you this when you append -Wall:
> gcc-4.4 -S t.c -Wall
t.c:2: warning: second argument of ‘main’ should be ‘char **’
t.c: In function ‘main’:
t.c:4: warning: implicit declaration of function ‘strtof’
t.c:8: warning: implicit declaration of function ‘printf’
t.c:8: warning: incompatible implicit declaration of built-in function ‘printf’
t.c:10: warning: control reaches end of non-void function