[comp.lang.c] Finding out what is defined

jwilliam@javelin.es.com (Jerry Williams) (03/18/91)

I would like to find out what is defined for a given compiler.
For example on a VAX running VMS vax is defined so the following works.
#ifdef vax
	printf("vax is defined !\n");
#endif
And the same works for a sun or a 386 using i386.
The question is, is there a way to find out what these are without
looking through the include files for a given system or guessing
at them? Is any of this documented somewhere or is it just something
everyone decided to do to be nice?

Jerry
-- 
Jerry Williams @ Evans & Sutherland  560 Arapeen Drive, SLC, Utah 84108
jwilliam@javelin.sim.es.com     or   jwilliam%javelin@sim.es.com
...sim.es.com!javelin!jwilliam  or   {decwrl, utah-cs}!esunix!jwilliam

dbrooks@osf.org (David Brooks) (03/19/91)

In article <1991Mar18.045748.6860@javelin.es.com>, jwilliam@javelin.es.com (Jerry Williams) writes:
|> I would like to find out what is defined for a given compiler.

I saw a clever solution on the net a while back; unfortunately I lost the
author.  Also, I added a few features.

-----------------------cut
#!/bin/sh

# Change these as needed
CC=/bin/cc
CPP=/lib/cpp

tfile1=/tmp/stra$$
tfile2=/tmp/strb$$.c

# My "strings" will read stdin, but the manpage doesn't guarantee that.
cat $CC $CPP > $tfile1
strings -a -2 $tfile1 |
 tr ' ' '\012' |
 sed 's/^-D//' |
 sort -u |
 awk '/^[a-zA-Z_][a-zA-Z0-9_]*$/ { printf "#ifdef %s\nZ__Z%s\n#endif\n", $0, $0 }' > $tfile2

$CC -E $tfile2 |
 sed -n 's/^Z__Z//p' |
 pr -i -t

/bin/rm $tfile1 $tfile2
exit
-- 
David Brooks				dbrooks@osf.org
Systems Engineering, OSF		uunet!osf.org!dbrooks
"It's not easy, but it is simple."