This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


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

RE: B19: gcc/libc bug with call to atof() (Win95)


gcc is a real C compiler when it compiles C, C allows you to use
undeclared functions, assuming that all undeclared functions are
"extern int".  Since a to f returns a double, not a float, I would
assume that there is a call setup/teardown problem that occurs due
to the incorrect assumption about the return type of the function.

To quote from K&R 2nd edition, page 72:

"...But if (as is more likely) atof were compiled seperately, the 
mismatch would not be detected atof() would return a double that
main() would treat as an int, and meaningless answers would result." 

None of this is a "bug" except in your code.

-Peter

Peter A. Vogel
Manager, SW Configuration Management
Chromatic Research, Inc.  
http://www.chromatic.com

> -----Original Message-----
> From: owner-gnu-win32@cygnus.com [mailto:owner-gnu-win32@cygnus.com]On
> Behalf Of Martin Hansen
> Sent: Tuesday, October 27, 1998 4:11 AM
> To: gnu-win32@cygnus.com
> Subject: B19: gcc/libc bug with call to atof() (Win95)
> 
> 
> Dear list,
> 
> in my version of gnu-win32 I encounter the following bug with
> gcc/libc.  
> I have the gnu-win32 version B19 running under Win95 (4.00.950 B).
> Within the gnu-win32 distribution I have the gcc version
> % gcc -v
> Reading specs from 
> C:\CYGNUS\B19\H-I386~1\lib\gcc-lib\i386-cygwin32\2.7-B19\specs
> gcc driver version 2.7-B19 executing gcc version 2.7-97r2aBeta
> 
> 
> 
> The following small program produces the bug:
> 
> /* test_atof.c */
> 
> #include <stdio.h>
> 
> main(int argc, char **argv)
> {
>    while (--argc)
>    {
>       printf("\narg %d is %s\n", argc, argv[argc]);
>       printf("arg %d : value as float %f\n", argc, atof(argv[argc]));
>       printf("arg %d : value as   int %d\n", argc, atoi(argv[argc]));
>    }
> }
> 
> /* End of file */
> 
> 
> 
> 
> Compile the program by
>     % gcc test_atof.c
> The program compiles and I don't get any error about the missing line
> "#include <stdlib.h>", where atoi() and atof() are declared.  (This is
> the bug, part1)
>  
> Try the program with
>     % test_atof  3.3 4.7
> The result is
> 
> arg 2 is 4.7
> arg 2 : value as float 0.000000
> arg 2 : value as   int 4
> 
> arg 1 is 3.3
> arg 1 : value as float 0.000000
> arg 1 : value as   int 3
> 
> which is wrong for the float value but right for the int value.  (This
> is the bug, part2).  First when you add the line '#include <stdlib.h>'
> to the program and recompile it, you get the desired behaviour.
> -
> For help on using this list (especially unsubscribing), send a message to
> "gnu-win32-request@cygnus.com" with one line of text: "help".
> 
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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