How can I find out cc or cpp symbols?

Ian F. Darwin ian at sq.com
Thu May 4 07:17:10 AEST 1989


> > Is there a way to find out what macros are defined?  It's particularly hard 
> > to predict which names will be _predefined_.
> 
> You may want to try this script.  I got the basic sed part from a friend
> who got it off of some notes group or other.  I changed it because we
> have a cpp which does not act as a filter; it needs an input file.

The script posted is a valiant attempt, but it's doomed to failure because
it contains some unstated and unfortunate assumptions about the private
internal data structure of C preprocessors.

(I'm ignoring the fact that it uses "strings", which is only standard in BSD
systems; it is at least possible to write a "strings" command for any given
a.out format, and there are versions kicking around for COFF and some other
formats).

You cannot validly make the assumption that all C preprocessors will store
each predefined string as a separate "strings"-able entity.  One cpp might
predefine them all as one giant string; another might encode them somehow;
another might have them in the "cc" command rather than in cpp. The SVID and
probably other standards have long advocated that "the recommended way to
invoke cpp is through the cc command"; pANS doesn't even require that cpp be
implemented as a separate program.

For a chuckle, try running it on gcc's cpp. The posted version of the script
first fails because it sets the path to exclude /usr/ucb, where "strings"
is on our system. When you fix this, it gets a syntax error (at least
on this system, a Sun 3 running SunOS 3.x).

To answer the original question, "to find out what macros are defined", read
the compiler's documentation. If the predefined macros aren't documented,
complain to your vendor. If that doesn't help, buy from a different vendor
next time, and let the losers (and maybe the appropriate newsgroups/mailing
lists) know why.

Ian F. Darwin, SoftQuad Inc., Toronto, utzoo!sq!ian, ian at sq.com



More information about the Comp.std.c mailing list