Bug 25284 - incorrect double value returned from function testo() called from main().
Summary: incorrect double value returned from function testo() called from main().
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.4.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-06 19:38 UTC by deadat
Modified: 2005-12-06 19:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
output of gcc -v (675 bytes, text/plain)
2005-12-06 19:40 UTC, deadat
Details
testo() function definition file from gcc --save-temps (144 bytes, text/plain)
2005-12-06 19:41 UTC, deadat
Details
main() function definition file from gcc --save-temps (177 bytes, text/plain)
2005-12-06 19:41 UTC, deadat
Details

Note You need to log in before you can comment on or make changes to this bug.
Description deadat 2005-12-06 19:38:32 UTC
inside main(), a call is made to function testo() which simply returns a double(1415.149).  The correct double value is returned only if main.c has #include <f.h>, which is where testo() is declared.

I've compiled two versions of this program, with and without the include line, withinclude.a.out and withoutinclude.a.out, respectively.  The assembled code varies slightly between the two, withoutinclude.a.out having the following extra three lines shown below (with xxx): 

        realnum=testo();
 8048384:       e8 2b 00 00 00          call   80483b4 <testo>
 8048389:       50                      push   %eax                    xxx
 804838a:       db 04 24                fildl  (%esp)                  xxx
 804838d:       8d 64 24 04             lea    0x4(%esp),%esp          xxx
 8048391:       dd 5d f8                fstpl  0xfffffff8(%ebp)		


fildl takes the pushed value (0xa) and stores it onto the floating point stack and then fetched by fstpl, which is then stored in realnum.


This code does NOT get generated if there is an #include <f.h> in main.c
Comment 1 Andrew Pinski 2005-12-06 19:40:07 UTC
The C standard says that if a function is not declared (prototyped) then implicately it returns the type of int.
Comment 2 deadat 2005-12-06 19:40:28 UTC
Created attachment 10422 [details]
output of gcc -v
Comment 3 deadat 2005-12-06 19:41:15 UTC
Created attachment 10423 [details]
testo() function definition file from gcc --save-temps
Comment 4 deadat 2005-12-06 19:41:33 UTC
Created attachment 10424 [details]
main() function definition file from gcc --save-temps
Comment 5 deadat 2005-12-06 19:45:18 UTC
(In reply to comment #1)
> The C standard says that if a function is not declared (prototyped) then
> implicately it returns the type of int.
> 

ok thanks, that makes sense =)