I have a large number of includes in my C program. During development I experimented with different ways of doing things so I bet there a number of libraries that I have included but are not used.
Does the compiler get rid of libraries that are not used? Is there a tool that can tell me? Even if the compiler does get rid of the code, it would tidy up the source if I can get rid of some things.
It’s not actually the compiler that decides whats finally goes into the executable, but the linker. Modern linkers are smart enough not not pull in code from a library unless the code is used. So you can link to hundreds of libraries, but if you don’t call any functions in them then they wont add any code to your program.
As for the header files, most doesn’t contain anything more than declarations and pre-processor macros, and those won’t add code by themselves. The biggest drawback with including many header files is that it will slow down compilation of the source file.