SUMMARY: C Compiler Predefined Manifest Definitions

David Brooks dbrooks at osf.osf.org
Wed Aug 22 13:38:50 AEST 1990


In article <191 at n4hgf.Mt-Park.GA.US> wht at n4hgf.Mt-Park.GA.US (Warren Tucker) writes:
>In article <185 at n4hgf.Mt-Park.GA.US> I wrote:
>> I would like to compile a list of pre-defined manifest constants
>> supplied by various C compilers.

Contributors might want to use this shell script, which I extended
from one I saw a while back; sorry, I forgot the original author.  It
finds all the strings stored in cc and cpp that are defined during a
normal "cc" command.  It won't find anything that's pieced together at
runtime.

----8<--------
#!/bin/sh

# Change these if appropriate:
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 |
sed '/^-D.*/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
----8<--------

Using this, cc on a DECstation gives:

	LANGUAGE_C
	MIPSEL
	__FILE__
	__LINE__
	bsd4_2
	host_mips
	mips
	ultrix
	unix

and on a VAX/Ultrix:

	__FILE__
	__LINE__
	bsd4_2
	ultrix
	unix
	vax

Get well soon, Warren.
-- 
David Brooks			dbrooks at osf.org
Systems Engineering, OSF	uunet!osf.org!dbrooks



More information about the Comp.lang.c mailing list