Finding out what is defined

David Brooks dbrooks at osf.org
Tue Mar 19 03:56:00 AEST 1991


In article <1991Mar18.045748.6860 at javelin.es.com>, jwilliam at 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 at osf.org
Systems Engineering, OSF		uunet!osf.org!dbrooks
"It's not easy, but it is simple."



More information about the Comp.lang.c mailing list