I want to print headers hierarchy in some automated way. The goal is to preserve order in header files inclusion.
I have tried to do the following in header "tmp1.h":
#ifndef HIERARCHY_PRINTING
#define HIERARCHY_PRINTING "start: "
#endif
#undef PREVIOUS_PRINTING
#define PREVIOUS_PRINTING HIERARCHY_PRINTING "->"
#undef HIERARCHY_PRINTING
#define HIERARCHY_PRINTING PREVIOUS_PRINTING "tmp1.h"
#ifndef _TMP1_
#define _TMP1_
// Some stuff
#endif
#undef PREVIOUS_PRINTING
#define PREVIOUS_PRINTING HIERARCHY_PRINTING ";"
#undef HIERARCHY_PRINTING
#define HIERARCHY_PRINTING PREVIOUS_PRINTING
And in "tmp.c":
#include <stdio.h>
#include "tmp1.h"
const char *str = HIERARCHY_PRINTING;
int main() {
printf("Headers hierarchy:\n");
printf("%s\n", str);
return 0;
}
But this doesn't compile:
tmp.c:7:19: error: ‘HIERARCHY_PRINTING’ undeclared here (not in a function)
tmp.c:7:19: error: expected ‘,’ or ‘;’ before string constant
I expected to see something like:
start: ->tmp1.h;
Where I'm wrong?