How can I find out cc or cpp symbols?

Curt Wohlgemuth curtw at hpcllca.HP.COM
Sat Apr 29 06:44:13 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.

Here it is:

-------------------------------------------------------------
#! /bin/ksh

SELF=`basename $0`
PATH=:/bin:/usr/bin:/usr/local/bin

TEMP=/tmp/t$$
OUTFILE=/tmp/out$$

trap "rm -f $TEMP $OUTFILE" 0 1 2

if [ $# -lt 1 ]; then
   echo "usage: $SELF <cpp> [ options ]"
   exit 1
fi

CPP=$1
shift
OPTIONS="$*"

strings -a -2 $CPP | sed '/^a-zA-Z0-9_/!s/.*/#ifdef &\
"%&"\
#endif/p' > $TEMP

$CPP $OPTIONS $TEMP > $OUTFILE 2> /dev/null
sed -n '/%/s/[%"]//gp' $OUTFILE | sort | uniq

rm -f $TEMP $OUTFILE

exit 0



More information about the Comp.std.c mailing list