Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for redundant included header files

Tags:

c++

c

Is there any way to find out all the redundant header files included in a C/C++ source file?

like image 782
Ravi Gupta Avatar asked Feb 26 '23 19:02

Ravi Gupta


2 Answers

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.

like image 130
Secure Avatar answered Mar 07 '23 02:03

Secure


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.

like image 31
Jens Gustedt Avatar answered Mar 07 '23 03:03

Jens Gustedt