So far I've got as far as:
#define ADEFINE "23"
#pragma message ("ADEFINE" ADEFINE)
Which works, but what if ADEFINE isn't a string?
#define ADEFINE 23
#pragma message ("ADEFINE" ADEFINE)
causes:
warning: malformed ‘#pragma message’, ignored
Ideally I'd like to be able to deal with any value, including undefined.
To display macros which aren't strings, stringify the macro:
If you have/want boost, you can use boost stringize to do it for you:
I'm not sure if this will do what you want, but if you're only interested in this to debug the occasional macro problem (so it's not something you need displayed in a message for each compile), the following might work for you. Use gcc's
-E -dD
option to dump#define
directives along with preprocessing output. Then pipe that throughgrep
to see only the lines you want:The command
gcc -E -dD -c test.c | grep ADEFINE
shows: