partial preprocessing

T

Theron Stanford

I've inherited a bunch of code that contains a lot of conditional
preprocessing commands.

Is there a way to run the preprocessor so that it processes the
conditionals but leaves the rest of the macros alone?

Take this code for an example:

/* start of code */

#define CONSTANT1 1
#define CONSTANT2 2

#if defined (A)
x = CONSTANT1;
#endif

#if defined (B)
x = CONSTANT2;
#endif

/*end of code */

I'd like to invoke the preprocessor with

cpp -DA

(and perhaps another option or two) and get back

/* start of code */

#define CONSTANT1 1
#define CONSTANT2 2

x = CONSTANT1;

/* end of code */

Since the #defined macros have useful names, I don't want them being
replaced by their values, namely:

/* start of code */

x = 1;

/* end of code */

Thanks in advance.

Theron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top