compilation - if 0 is compiled in c program -
i'm trying removed unused code program - can't delete code now, want disable start.
let's have following code:
if (cond){ dosomething() }
and cond
false dosomething
never called.
i want like:
#define remove_unused_code 0 if (cond && remove_unused_code){ dosomething() }
now obvious (and compiler) code unused.
will compiler remove if
condition or leave , never in?
p.s.: can't use #if 0
purpose
gcc explicitly remove conditional blocks have constant expression controlling them, , the gnu coding standards explicitly recommend take advantage of this, instead of using cruder methods such relying on preprocessor. although using preprocessor #if
may seem more efficient because removes code @ earlier stage, in practice modern optimizers work best when give them information possible (and of course makes program cleaner , more consistent if can avoid adding phase-separation dependency @ point isn't necessary).
decisions very, very easy modern compiler make - simplistic tcc perform amount of dead-code elimination; powerful systems llvm , gcc spot this, , more complex cases you, human reader, might miss (by tracing lifetime , modification of variables beyond looking @ single points).
this in addition other advantages of full compilation, fact code within if
checked errors (whereas #if
more useful removing code would be erroneous on current system, references nonexistent platform functions).
Comments
Post a Comment