0
If we don't insert the header files the program is still running why?
void main() { Printf("hello") ; }
4 odpowiedzi
+ 8
Excellent answer C++ Soldier (Babak)
+ 6
Answer from mighty SO! the high-voted answer says:
"Definition of printf() is there in libc.so and the dynamic linker will take care of it even if you don't include the header file. During compile time, printf() will be an undefined symbol and it assumes that it may find the definition later on in libc. The header file will just give the proto-type and suppress the compiler(warnings) stating that the definition of the prototype is present in glibc. So basically, the header files are included just to make sure that the definitions are available in our libraries, to help the developer."
____
https://stackoverflow.com/questions/4654147/without-including-stdio-h
+ 2
Thank you very much your answer gave me lot of help to understand linker
+ 2
Note, warnings still occur. Using a syntax error to show them on SoloLearn, here's the compiler output for the above code:
warning: return type of 'main' is not 'int' [-Wmain]
warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
warning: incompatible implicit declaration of built-in function 'printf'
note: include '<stdio.h>' or provide a declaration of 'printf'