You are here:

C++/Compiler Directives Removal

Advertisement


Question
Hi,

I have a lot of Pre-Processor compiler directives in my source code. I want to remove some of those from the source, but I want an automated way to do that. I don't know any software which can this.

Basically, if I have the following sample source code:
#if (COMPILING_WAY == 3)
nPeople = 33;
#else
nPeople++;
#endif

I want an automated way to convert all my source code to the way the compiler would see it if COMPILING_WAY == 3. That means:
nPeople = 33;

..instead of the previous sample.

I hope I made it clear enough.


Thanks in advance.

Answer
Compilers usually have more than one pass through the code. The first pass usually is to do what you want. They usually have an option to let you export the intermediate files.
Therefore, depending on the compilet that you use, find the way you can tell the compiler to save the file after it passes the first pass (that is after it converts macros to codes).
You might even be able to ask compiler to save the assembly language corresponding to your code. That happend usually in the second pass of compiling.
The last pass is linker that converts assembly to machine code.
I hope this helps.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Sam

Expertise

You may ask me about simple to complicated C/C++ programming methods/style and most like questions about network programming in C++.

Experience

I'm a professional programer in C++ and network/internet programming.

©2016 About.com. All rights reserved.