Possible Duplicate:
Why #include <stdio.h> is not required to use printf()?
Both printf and scanf have been declared in stdio.h. But they work even without that, dropping just a warning message? What’s the theory behind this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Calling a function without declaring it will create an implicit declaration based on the parameters you give and an assumed return type of
int. This lets it get past the compilation stage, since the function could exist somewhere else that isn’t known until link time — C didn’t always have function prototypes, so this is for backwards compatibility. (In C++, it’s an error, and in C99 GCC gives a warning.)If you look at the man page (on FreeBSD and Darwin, at least) for
printf,scanf,puts, etc., it says that it comes from the “Standard C Library (libc, -lc)”. GCC implicitly links with the standard C library. If you link with the-nostdlibflag, you’ll get the “undefined symbols” error that you’re expecting.(In fact, when I turn off
libc, my GNU/Linux system complains about the absence of_startas well, and my OpenBSD system complains about_start,__guard, and__stack_smash_handler.)