Will C compiler attach the whole object code of the header file

ccompiler

When you compile a C source code does the compiler convert the whole header file to object code or just the functions of the header file you use?

Like for example, in the header file #include stdio.h, there are printf(); and scanf(); but even to use one of them, you have to include the header file "stdio.h", so when you compile a C source code which uses only printf(); but doesn't use scanf();, will the compiler also include the object code of scanf(); and other functions of "stdio.h" in the file?

Best Answer

The compiler will generate code for everything.

The linker may (and usually does) not include code of unused functions in the final executable.

Implementation, of course, varies from linker to linker.