Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
When the following little C program is compiled with gcc it does not get a compile error even though the function atof is undefined. If I change it to xatof then it goes get an "undefined reference" error. (I know that atof is a library function, and I know that it resides in stdlib.h. But since I did not include stdlib.h I would think that it would give me an error). What am I missing here???
The compiler doesn't know about libraries linked later, so the only thing it could issue is a warning. Implicit declaration is allowed in C. But, try compiling with "-Wall", i'm quite sure you will get your implicit declaration warning
I have learned to never use a name from the common C libraries.
There are too many paths that the compiler can get to them.
Some of the headers call each other so deep, that I cannot track down
which names might be safe to use.
I suspect the GNU compiler knows about the name even it is not defined or declared. It has many non-standard enhancements. Try to find it in the "info GCC", it might be mentioned.
Test this again with some other stdlib names. I suspect it will work with some and not others. If the compiler is getting to the stdlib header by some sneak path then all the names will behave the same.
Last edited by selfprogrammed; 07-25-2010 at 03:56 PM.
well, right, but the OP just misses an error message. the explanation for this is that the linker obviously finds a symbol "atof" somewhere in the standard libs that are linked by default, so it doesn't complain. And, as strange as this may sound, "implicit declaration" (by JUST using a function without declaring it first) is allowed in ISO C.
But, compilers can (and should) issue warnings about implicit declarations because they are a common source of errors ....
Using gcc -Wall does give me an error message, and I thank Zirias for that info. I will use that from now on. I might add, parenthetically, that whatever atof it did come up with does not work. If it had worked, I would have never even realized the error. (The error being not to use #include <stdlib.h>)
That's good practice. I use "-std=c89 -pedantic-errors -Wall -Werror" on any ISO C code i plan to release to the public Sometimes this complains about things I actually wanted that way, but there's always a way around
I might add, parenthetically, that whatever atof it did come up with does not work.
Implicit declaration makes the compiler assume the function returns an int. So it called the correct atof (which actually returns a double) then it converted the returned value from int to double. When the returned value wasn't actually an int, converting it from int to double gives you garbage.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.