Why declarations in <stdio.h> aren't implemented?

Click For Summary
In C programming, header files (.h) contain function declarations and constants but typically do not include implementations, except for inline functions. When a developer includes a header file like #include <foo.h>, they must implement the declared functions in their .c file. However, including standard headers like #include <stdio.h> allows the use of functions such as printf() without needing to implement them in the .c file. This is because during the compilation and linking process, the linker searches through various libraries for the actual definitions of these standard functions, which are provided by the C standard library. This distinction clarifies why some functions can be used directly after including their respective headers, while others require implementation.
CGandC
Messages
326
Reaction score
34
In the C programming language any .h file is a file that contains constants and/or function declarations ( but no implementations, besides inline functions ). That means that when I write #include <foo.h> at the start of my .c file, I'll have to implement all those function declarations ( similar to implementing an interface in Java ).

But if I write for example, #include <stdio.h> at the beginning of the code, then I read that by doing this I am now able to call input/output related functions such as printf() ; I don't know how calling these functions is possible right now because I understood that after adding #include <stdio.h> to the beginning of the code then I have only added function declarations from stdio.h into my .c file and not yet implemented these declarations ( haven't defined them yet ) - this means that I have to implement those functions in my .c code ; however, a .c file compiles without implementing printf() for example.

So I haven't really understood, If #include <foo.h> just copies the contents of the declarations in foo.h file - function declarations which I have to implement in the .c file, then why when including #include <stdio.h> In my .c file don't have to implement functions declared in that header such as printf() ?

Thanks in advance for any help!
 
  • Like
Likes Wrichik Basu
Technology news on Phys.org
When you compile (and link) your code, there is a long list of libraries, some standard and some user-supplied, that the linker will look through for the function definitions. That is where it finds the definitions of those standard functions.
 
  • Informative
  • Like
Likes Wrichik Basu, Mark44, berkeman and 1 other person
I understand now, thanks!
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

Replies
81
Views
7K
Replies
14
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
6
Views
2K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
65
Views
5K