Reputation: 2155
Let's say I have a C program which only uses functions from stdio.h
.
Now, if I include unwanted headers like stdlib.h
, errno.h
, etc. and compile the program, then will these unwanted headers have an impact on code segment?
I say "unwanted headers" because the program does not use functions declared in these headers.
Upvotes: 3
Views: 358
Reputation: 411
Head files are used for compiler, if there are "unused head files", compile time will be low when the project is small.
But for a big project, it should be well handled. And you know "Simple is Beauty!"
And it's nothing to do with final binary product.
Upvotes: 1
Reputation: 674
No, your program only pulls in code that it references to. Including a header you don't use will be optimized out of the final code.
I should clarify, "Including a header you don't use will not result in 'extra waste' in the final product." No code is optimized out because no code is actually generated(since it's not referenced).
Upvotes: 2