This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: bug: returning a float doesn't work
- To: Juan Carlos Pizarro =?unknown-8bit?Q?M=E9ndez?= <jcpizarro1977 at mixmail dot com>
- Subject: Re: bug: returning a float doesn't work
- From: "Zack Weinberg" <zackw at stanford dot edu>
- Date: Wed, 9 May 2001 10:41:09 -0700
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <20010509192252.HM.900000000002onq@mixmail.com>
On Wed, May 09, 2001 at 06:22:52PM +0000, Juan Carlos Pizarro M?ndez wrote:
>
> float f(float x) { /* this function doesn't
> work */
> return ((x * x) / 2.0);
> } /* float is impossible into %eax% until now
> */
>
> void g(float *y,float x) { /* it does work */
> *y = ((x * x) / 2.0);
> }
>
> main() {
> float y = 0.0;
> y = f(3.0);
> printf("%f\n",y); /* fail */
> g(&y,3.0);
> printf("%f\n",y); /* ok */
> }
>
$ gcc test.c
$ ./a.out
4.500000
4.500000
with all of
2.95.4 20010502 (Debian prerelease)
3.0 20010506 (prerelease)
3.1 20010507 (experimental)
The only change I made to your code was to add an #include <stdio.h>
at the top. I believe that the program is correct and compiled
correctly, except of course that you fall off the end of main.
I do not know what "float is impossible into %eax% until now" means.
It's possible that you are confused because float values are returned
in %st(0), not %eax, on ix86 machines.
--
zw ...It's not easy for cognitive scientists to get grants if they
are working on questions of any theoretical interest. (To ensure
this is a main function of the institution of peer review.)
-- Jerry Fodor, _The Mind Doesn't Work That Way_