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

  • #1
311
32
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
  • #2
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
  • #3
I understand now, thanks!
 

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

Back
Top