| Summary: | atof incorrect when stdlib.h not #include'd | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Tom Garcia <veri2> |
| Component: | bin | Assignee: | freebsd-bugs (Nobody) <bugs> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | 4.3-STABLE | ||
| Hardware: | Any | ||
| OS: | Any | ||
> atof returns random odd numbers when stdlib.h not #include'd, otherwise seems
> to work fine.
Calling std library functions (especially those returning anything except
"int") without the appropriate header include is a bug in your program, and
has nothing to do with FreeBSD or any other OS. You would get similar errors
from a Windows C compiler.
This particular instance is documented in the SYNOPSIS section of the man page
for atof.
This bug would also have been picked up by compiling with the "-Wall" flag.
This PR can be closed.
State Changed From-To: open->closed Many, many functions depend on some header file or other to be included in order to function properly. This has been well-documented in both the C standard, and the respective manpages. In this particular case, atof(3) fails simply because if there is no prototype, the compiler assumes that the function returns int. You might explicitly declare atof() to return double, or, much better, you should include the appropriate header files. |
atof returns random odd numbers when stdlib.h not #include'd, otherwise seems to work fine. Fix: #include <stdlib.h> How-To-Repeat: /* note stdlib.h is not being included */ int main() { printf("%g\n", atof("3.95")); }