Print all defined macros

I'm trying to reorganize a piece of legacy code, and I need a snapshot of all the macros defined at a specific point in the source. The code imports an absurd amount of headers, etc., and it's a little tedious to track them manually.

Sort of

#define FOO 1


int myFunc(...) {
    PRINT_ALL_DEFINED_THINGS(stderr)

    /* ... */
}

Expected Somewhere Out

MACRO: "FOO" value 1

I use gcc but have access to other compilers if it is easier for them to complete this task.

EDIT:

A related question does not give me the correct output for this:

#include <stdio.h>

#define FOO 1

int main(void) {
    printf("%d\n", FOO);
}

#define FOO 0

This prints very clearly 1at startup, but gcc test.c -E -dM | grep FOOgives me 0

+4
source share
1 answer

Reset all definitions you can run:

gcc -dM -E file.c

Check GCC dump preprocessor determines

, ( ), .

"-Wunused-macro", , .

+1

Source: https://habr.com/ru/post/1545845/


All Articles