Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are unused includes harmful in C/C++?

Tags:

c++

What are the negative consequences of unused includes?

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

like image 852
anio Avatar asked Oct 27 '11 16:10

anio


People also ask

What takes care of include files in C?

The #include directive tells the C preprocessor to include the contents of the file specified in the input stream to the compiler and then continue with the rest of the original file. Header files typically contain variable and function declarations along with macro definitions. But, they are not limited to only those.

What happened if standard library is not present in C?

Without the standard library, you're entire reliant on your own code, any non-standard libraries that might be available to you, and any operating system system calls that you might be able to interface to (which might be considered non-standard library calls).


1 Answers

  • 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.
like image 55
mloskot Avatar answered Oct 02 '22 22:10

mloskot