I'm trying to figure out if it is possible to print headers hierarchy using just the C language itself (like in quines). The goal is to get a set of trees where root is a .c
file and leafs are the basement headers which doesn't include any other headers. The possible output:
start: header1.h->header2.h->header3.h;header1.h->header4.h; end
which means for example that header1.h
includes two headers: header2.h
and header4.h
.
It looks like my attempt to do this Print headers hierarchy doesn't work at all. But is there some way using preprocessor or any other language feature to print headers hierarchy? Or should I just use Python script?
EDIT:
The solution proposed by @stijn in comments to use compiler option -H
actually doesn't do the full job since it doesn't print headers twice. So for headers included later the hierarchy will be partial.
The question How to tell where a header file is included from? is about absolute paths of headers and where compiler actually finds on disk the particular header. My question is about headers inclusion hierarchy - which header does include which headers? So it doesn't matter where on disk headers lie.