While reading about compilation in C, got stuck understanding header files. I've googled my best but still confused. Please explain:
- If we have a main program (
main.c
), which calls for a certain function, and an additional program (mod.c
), which contains the implementation of that function, what's the point of making an extra header file (mod.h
)? I'm aware that it contains description of that function (and presumably many other functions) but still ... what's the point? Why can't I just prepare an objective file (mod.o
) in advance and keep it handy for any of my programs to use when needed? - How this
#include "mod.h"
works? The compiler sees the file, checks description of the function inside and ... what's next? How does it know where to find the function source code? Does it read themod.c
file and copy-pastes it to themain.c
file? - Where is the source code of standard functions like
printf, scanf
etc. in the Linux OS?
I'm sorry if my questions sound dumb.