c++ - Is an empty function called at all in optimised code? -
if test macro not defined, know whether there performance difference in these 2 pieces of code:
void func1(int a) { ... } #ifdef test func1(123); #endif
and:
void func2(int a) { #ifdef test ... #endif } func2(123);
with test not defined, func2 become , empty function complier should not call @ all, isn't it?
thank you.
it pretty comes down whether particular call func2
inlined or not. if is, optimizing compiler ought able make inlined call empty function same not calling @ all. if isn't inlined, it's called , returns immediately.
as long function definition available in tu containing call func2
, there's no obvious reason won't inlined.
this relies on fact 123
literal, evaluating arguments of call has no side-effects. args have evaluated if function call has no effect, so:
int = 0; /* 'i' incremented, if call optimized out */ func2(++i); /* 'i' not incremented when 'test' undefined */ #ifdef test func1(++i); #endif
Comments
Post a Comment