Question

I didn't found any reference to what I'm looking for so probably best is to ask here. Lets say I want to have 2 version of my program.

Now I do something like:

#define MY_VER 0 //0 or 1 depending on which version I want to compile

Function1();
if(MY_VER)
Function2();  //It will run only if MY_VER is set

Now I have lots of code as such, but even when I compile it with MY_VER=0 some of the strings in "my" functions are still in exe. How to programaticaly exclude some of the lines, so they are completly unexistant when I want it to be like that.

Was it helpful?

Solution

One obvious possibility would be to use the preprocessor:

#if MY_VER
Function2();
#endif

Less obvious (but usually equally effective) is to just turn on the optimizer. What you have there is dead code, which most compilers can identify and remove quite effectively.

OTHER TIPS

You're looking for the pre-processor "if":

#if(MY_VER)

Note the "#". Don't forget to close with #endif.

You can use the preprocessor to remove them, so the compiler doesn't even see those lines.

Use #if MY_VER ... #endif

If you want to be totally sure that some functions aren't included, use conditional compilation not only for the calls to those functions, but for the function definitions themselves.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top