I am new to C and am just learning the basics of modularising my code for neatness and maintainability. I am reading a lot of people saying not to include .c
files directly but instead to use .h
files with associated .c
files.
My question is, when writing a library which is exposed/included via its .h
file - does the compiler dedupe common includes or are the included each time they are referenced?
For instance in my above application, I am using printf
in my main
and also in my foo
library.
When running:
gcc -o app main foo/foo.c && ./app
I get the expected outputs printed to the console, however does the compiler remove duplicates of the <stdio.h>
include or is it included once for main.c
and once again for foo.c
?