This is the mail archive of the gcc-bugs@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]

[Bug c/50695] double comparison broken after computation


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


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