Is there any way to find out all the redundant header files included in a C/C++ source file?
Be aware that redundant includes may be a good thing here, because it provides self-containment of header files. I.e. if B includes A, and C includes both B and A:
headera.h
headerb.h
#include "headera.h"
headerc.h
#include "headerb.h"
#include "headera.h"
you could argue that the inclusion of A is redundant in C, since it is already provided by the inclusion of B. But in fact it makes C independent from the inner structure of B. Removing it would make C dependent on B to include A.
I use doxygen (together with graphviz) to get the include graph. Then the `redundant' includes are the transitive arcs, i.e arcs that introduce a short cut on a longer path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With