Note that library header files like stdio.h
only contain declarations for functions like printf
; they do not contain the actual code for those functions. The actual code for functions like printf
is added at link time, when all the object files and relevant libraries are combined to form the final executable.
Including source files like in your example generally considered bad practice, although there may be specific use cases for it; I just can't think of any good ones offhand. You run a greater risk of duplicate definition errors, and you wind up rebuilding code unnecessarily. The compiler may have a limit on how much code it can digest in one sitting; including source files that include source files that include source files may result in extremely long build times or worse. It's been a while, but I've seen compilers choke on very large files, especially if you're trying to optimize the output.
The beauty of splitting code up into multiple source files is that if I only change something in one file, I (usually) don't have to rebuild the entire project (of course, this depends on what was changed); I only have to recompile that one file and relink.