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

AI Thread 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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top