tags:

views:

71

answers:

2

Hi,

I do have say #if A in code and made a lib.

Now for some reason i do want to take out code from lib containing #if A without recompiling the lib.

Can i do this using some command.

Regards, Kiran

+1  A: 

Just don't use a macro, use a variable.

Hans Passant
Yes indeed, but for the record it's worth mentioning the probably insignificant run-time cost of checking the boolean state of A each time, where-as #if A is resolved at compile-time.
Tony
You'd have to use an `extern`ally defined variable, or you'd have the same problem with having to recompile. Of course, having a library which requires a variable defined in the user code is a "code smell".
James Curran
Basically I do want to reduce the image size without recompiling the code. Using variables will have the code as it is in the image hence increase the size. Compiling out or disabling with some command will actually reduce the size.
A gigabyte of RAM costs twenty bucks. If your time is worth less than that, go ahead and keep recompiling.
Hans Passant
+5  A: 

So you're saying you had a .c file like this:

<list of code>
#if A
 <optional code>
#endif

And you compiled this .c file to a compiled library (a .lib, .dll, .so, .o or .a), and you want to remove the <optional code> from the compiled library? It can't be done, because the #if A directive doesn't exist in the compiled library; it is statically processed at compile time (in theory, before compile during preprocessing) and either wholly included or wholly excluded from the compiled library. The only way to change it is to recompile.

Philip Potter