www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/10/29/12:24:47

From: pvogel AT chromatic DOT com (Peter A. Vogel)
Subject: RE: B19: gcc/libc bug with call to atof() (Win95)
29 Oct 1998 12:24:47 -0800 :
Message-ID: <001701be0286$b612a120$3565a8c0.cygnus.gnu-win32@dolphin.chromatic.com>
References: <3635B86F DOT 93BBC51A AT widex DOT com>
Mime-Version: 1.0
To: "Martin Hansen" <m DOT hansen AT widex DOT com>, <gnu-win32 AT cygnus DOT com>

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 AT cygnus DOT com [mailto:owner-gnu-win32 AT cygnus DOT com]On
> Behalf Of Martin Hansen
> Sent: Tuesday, October 27, 1998 4:11 AM
> To: gnu-win32 AT cygnus DOT 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 AT cygnus DOT com" with one line of text: "help".
> 
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019