Subject: toolchain/36664: a simpler and safer way to find gcc's pre-defined macros
To: None <email@example.com, firstname.lastname@example.org,>
From: Greg A. Woods <email@example.com>
Date: 07/17/2007 23:20:00
>Synopsis: a simpler and safer way to find gcc's pre-defined macros
>Arrival-Date: Tue Jul 17 23:20:00 +0000 2007
>Originator: Greg A. Woods
>Release: NetBSD 4.0_BETA2
Planix, Inc.; Toronto, Ontario; Canada
System: NetBSD 4.0_BETA2
Since gcc-4 now uses a built-in pre-processor exclusively it is
no longer possible to discover the likely pre-defined macros
simply by examining the cpp0 command parameters shown when the
"-v" option is used.
After rather extensive searching I find the gcc(1) manual
suggests using the "cpp" command and asking it to dump its list
of defined macros after parsing an empty file.
However there's a simpler, and thus safer, way to do it without
having to create a custom empty file. "cpp" doesn't care what
it's filename parameters look like and by default it'll even
read from stdin.
I put the alternate section in since due to what would seem to
be an obvious design flaw in the gcc/cc wrapper program it fails
to use argv to determine its own name and thus has to be
specially compiled to produce a custom "cpp" binary. In reality
the "cpp" variant could simply be ignored since this is of
course the gcc(1) manual page, not the cpp(1) manual page.
The sort is there because there are so many new pre-defined
macros in gcc-4 that it's impossible to read the list otherwise,
and really the example should suggest a "| more" too since there
are far more than fit on even a largish window, but generally I
assume (perhaps unwisely) that users are smart enough to try
again with a pager if they need to.
The redirection to read /dev/null from stdin is probably safest
just in case "gcc -E" suddenly does start to care what its
filenames look like again.
RCS file: /cvs/master/m-NetBSD/main/src/gnu/usr.bin/gcc4/gcc/gcc.1,v
retrieving revision 1.1
diff -u -r1.1 gcc.1
--- gnu/usr.bin/gcc4/gcc/gcc.1 10 May 2006 22:48:13 -0000 1.1
+++ gnu/usr.bin/gcc4/gcc/gcc.1 17 Jul 2007 21:42:38 -0000
@@ -6272,13 +6272,20 @@
directives for all the macros defined during the execution of the
preprocessor, including predefined macros. This gives you a way of
finding out what is predefined in your version of the preprocessor.
-Assuming you have no file \fIfoo.h\fR, the command
+The following command:
-\& touch foo.h; cpp -dM foo.h
+\& cpp -dM < /dev/null | sort
+will show all the predefined macros and their values. Alternately to be
+sure the exact same built-in preprocessor code is running you can use
+\& gcc -dM -E - < /dev/null | sort
-will show all the predefined macros.
.IP "\fBD\fR" 4
.IX Item "D"
Like \fBM\fR except in two respects: it does \fInot\fR include the