Confused about header #include

closed account (SwTk92yv)
Suppose I #include <stdio.h> in my source file. I don't have stdio.cpp in my project.

From what I understand, all source files in a C++ project get compiled and in that process all #included headers are "copy-pasted" in there. That way, say, Cpp1.cpp gets info (from header.h) about functions that are in the project (in one of the cpp files). That's alright.
But what if I #include <stdio.h>? I don't have stdio.cpp in my project (I didn't add it myself), but I still can use functions from there once I merely #include <stdio.h>. How does a compilator know to add specifically "stdio.cpp" into the whole compilation?
Most compilers automatically links the standard library. With GCC you can prevent the standard library from being linked by passing the -nostdlib flag.
How does a compilator know to add specifically "stdio.cpp" into the whole compilation?
For that libraries exists. They contain the already compiled code and the linker add them to your program.

For non standard libraries you need to tell the linker the appropriate files.
closed account (SwTk92yv)
Thank you guys for the answers.
C++ contains ALL features of C. Therefore, using certain C functions is allowed without writing the C headers. However, stdio.h is referred to in C++ as cstdio.h, and will be included as #include <cstdio>. The c there indicates that the header file is inherited from C
Topic archived. No new replies allowed.