Is there a way to make the GNU C Preprocessor, cpp (or some other tool) list all available macros and their values at a given point in a C file?
I'm looking for system-specific macros while porting a program that's already unix savvy and loading a sparse bunch of unix system files.
Just wondering if there's an easier way than going hunting for definitions.
With gcc, you can use the "-dD" option to dump all the macro definitions to stdout.
To list "their values at a given point in a C file" using macros, there is two that can demonstrate a given point in a C file, especially when compiled, and would be deemed useful for tracing a point of failure...consider this sample code in a file called foo.c:
If that code logic was used several times in this file, and the call to
malloc
was failing, you would get this output:The line number would be different depending on where in the source, that logic is used. This sample serves the purpose in showing where that macro could be used...
Why not consult the section on Predefined-macros? Do you need this for building a project or some such thing?
Here is a link to a page with an overview of command-line options to list predefined macros for most compilers (
gcc
,clang
...).I don't know about a certain spot in a file, but using:
Dumps all the default ones. Doing the same for a C file with some
#include
and#define
lines in it includes all those as well. I guess you could truncate your file to the spot you care about and then do the same?From the man page: