I'm studying C language nowadays. In this book, it is said that the "compiler provides these library functions: 'printf','scanf'…".
I can't understand. Those functions are defined in the header file <stdio.h>
aren't they?
Why does this book explain those functions are provided by the compiler?
printf
, scanf
, and the other standard library functions are provided as part of the implementation.
A C implementation is made up of several components. The compiler is just one of them. The library is another; it consists of headers (commonly provided as source files like stdio.h
) and some form of object code files containing the code that actually implements the library functions.
The header stdio.h
only declares these functions; it doesn't define them. The declaration of printf
is something like:
int printf(const char *format, ...);
The definition of printf
is the code that actually does the job of parsing the format string, accessing the arguments, and sending the formatted output to stdout
. That's typically (but not necessarily) written in C and provided as some kind of linkable object code.
For some C implementations, the compiler and the library are provided by the same organization. For others, they might be provided separately (for example MinGW combines the gcc compiler with Microsoft's library).
The functions are provided by the standard library, which is a collection of precompiled code that is typically written by the compiler authors (but it is indeed not a part of the compiler itself).
Note, though, that the functions are only declared in the header files. The definition resides in source files that have already been compiled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With