Article View: gnu.gcc.bug
Article #5925Is gcc sometime returning a double in a float prototyped function ?
From: Alexandre Petit-Bianco
Date: Wed, 29 Jan 1997 00:00
Date: Wed, 29 Jan 1997 00:00
54 lines
1788 bytes
1788 bytes
gcc version: 2.7.2
os version: linux 2.0.18
-------------------------------------------------------------------------------
float fooFloat( float, float );
void main()
{
float a, b, f;
a = 3.14156;
b = 0.123456789;
f = 123126.266560;
printf( "%f\n", fooFloat( a, b+123123 ) );
f -= fooFloat( a, b+123123 );
printf( "%10.15f\n", f );
}
float fooFloat( float a, float b )
{
#ifdef NO_BUG
float f = a+b;
return( f );
#else
return( a+b );
#endif
}
-------------------------------------------------------------------------------
On my linux box, compiling like:
$ gcc foo.c
$ a.out
Gives a non zero result at the second printout
Compiling like:
$ gcc -DNO_BUG foo.c
$ a.out
Gives a zero result at the second printout.
Playing around with that and having a look at the generated assembly
language, it seems to me that GCC is, when NO_BUG is not defined,
returning a double (or rather keeping a double, thanks to the Pentium
FPU architecture) as the result of the evaluation of a+b. Explicitly
storing the result into a float makes the function return a float. It
doesn't work though, if you force the cast in the a+b return
statement.
I'd be grateful to receive some feedback about this submission.
Technical Details
Message-ID:
<9701300317.AA05731@lighter.silvaco.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,41280cb232a4ad7c,start X-Google-Attributes: gid113d02,public From: alexp@silvaco.com (Alexandre Petit-Bianco) Subject: Is gcc sometime returning a double in a float prototyped function ? Date: 1997/01/29 Message-ID: <9701300317.AA05731@lighter.silvaco.com> X-Deja-AN: 213148978 sender: bug-gcc-request@prep.ai.mit.edu x-gateway: relay6.UU.NET from bug-gcc to gnu.gcc.bug; Wed, 29 Jan 1997 22:18:44 EST newsgroups: gnu.gcc.bug