Are unused includes harmful in C/C++?

What are the negative consequences of unused includes?

I'm aware they result in increased binary size (or do they?), anything else?


  • Increases compilation time (potentially serious issue)
  • Pollutes global namespace.
  • Potential clash of preprocessor names.
  • If unused headers are included from third-party libraries, it may make such libraries unnecessarily maintained as dependencies.

They don't necessarily increase binary size, but will increase compile time.


The main problem is clutter. These are the three main aspects in which the clutter manifests:

  1. Visual pollution; while you are trying to figure other includes that you do need.

  2. Logical pollution; it is more likely to have collision of functions, more time to compile (it might be really small for a couple of includes, but if it becomes a "policy" to not cleaning up unneeded includes, it might become a significant hurdle).

  3. Dependency opacity; since there are more headers to analyze is it harder to determine the dependency cycles in your code. Knowing what are the dependencies in your code is crucial when your codebase grows to any significant level beyond the hobbyist level.


Generally speaking, yes, it does cause some problems. Logically speaking, if you don't need it then don't include it.

  • Any singletons declared as external in a header and defined in a source file will be included in your program. This obviously increases memory usage and possibly contributes to a performance overhead by causing one to access their page file more often (not much of a problem now, as singletons are usually small-to-medium in size and because most people I know have 6+ GB of RAM).

  • Compilation time is increased, and for large commercial projects where one compiles often, this can cause a loss of money. It might only add a few seconds on to your total time, but multiply that by the several hundred compiles or so you might need to test and debug and you've got a huge waste of time which thus translates into a loss in profit.

  • The more headers you have, the higher the chance that you may have a prepossessing collision with a macro you defined in your program or another header. This can be avoided via correct use of namespaces but it's still such a hassle to find. Again, lost profit.

  • Contributes to code bloat (longer files and thus more to read) and can majorly increase the number of results you find in your IDE's auto complete tool (some people are religiously against these tools, but they do increase productivity to an extent).

  • You can accidentally link other external libraries into your program without even knowing it.

  • You may inadvertently cause the end of the world by doing this.