Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimizing Headers

Tags:

c++

I'm looking for a tool which can do at least one of two things.

  • Guess what headers might be unused and can be removed.
  • Guess which headers should be included in a file, but are included indirectly through inclusion of other files. Thus allows proper compilation of the file.

Is there such a tool?

like image 730
ronag Avatar asked Feb 15 '26 02:02

ronag


2 Answers

You could use GCC warnings "-Wmissing-declarations" and "-Wredundant-decls". It's not precisely what you want, but might help a lot.

like image 106
Šimon Tóth Avatar answered Feb 17 '26 14:02

Šimon Tóth


A colleague of mine wrote a very simple script to achieve part of this (and slow too...).

Basically the idea is to try to comment each include in turn and then try to compile the object, it doesn't deal with include within headers but already remove a substantial number of unused files :)

EDIT:

Pseudo code of the algorithm

for s in sourceFiles:
  while t := commentNextInclude(s):
    if compilationOk(): s := t

As I said, comment each #include in turn, and each time check if the program still compiles, if it does, validate the commenting, and move on to the next one.

I don't have the rights to disclose the script source though.

like image 20
Matthieu M. Avatar answered Feb 17 '26 15:02

Matthieu M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!