[comp.lang.c] #DEFINEs and how to process them out

gest_ss@uhura.cc.rochester.edu (Gavin Stark) (12/13/90)

Question:

	How do I get the following effect:  I want a program to scan
through my C source and process the #ifdef statements.  Like the
following

#define TRUE
#ifdef TRUE
int a;
#endif

should give me just:
int a;

The program I have has LOTS of ifdefs and other such constructions.  Is there
a way to parse out just the ones that actually get compiled?  Thanks for
any suggestions.

Gavin Stark
gest_ss@uhura.cc.rochester.edu

tlg@ukc.ac.uk (T.L.Goodwin) (12/13/90)

From article <11085@ur-cc.UUCP>, by gest_ss@uhura.cc.rochester.edu (Gavin Stark):
> Question:
> 
> 	How do I get the following effect:  I want a program to scan
> through my C source and process the #ifdef statements.  Like the
> following
> 
> [ example deleted ]

Under UNIX:

	cc -E file.c

under VMS:

	cc file.c /preprocessor_only=sys$output

sends what you require to the standard output.  Sending it to a file is
left as an exercise for the reader...

Tim.

karl@ima.isc.com (Karl Heuer) (12/14/90)

In article <2362@ukc> tlg@ukc.ac.uk (T.L.Goodwin) writes:
>[Someone asks:]
>>I want a program to scan through my C source and process the #ifdefs...
>
>Use   cc -E file.c   [or equivalent]

The example made the question ambiguous.  If the intent was to process the
#ifdef directives *without* expanding all the #defines, then the problem is
more interesting.  Things to check: `unifdef', `cpp -S'; the comp.sources
archives; the Free Software Foundation.

Exercise: if none of the above work, design and implement such a tool and
release it as Freeware.

Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint