Re: selective function call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/30/05, Hayim Shaul  wrote:
>       int call_me();
>       extern bool decide;
>       inline void log(int i) {
>               if (decide)
>                       printf("log: %d\n", i);
>       }
>        int main(int,char**) {
>                log(call_me());
>        }
>  compiled and linked it with -O3 and call_me was printed!

Hi.
 The evaluation of call_me() should be done anyway (regardless of inlining).
This is the rule of the c++ language (applicative order of evaluation).
I didn't mean that you can save such an evaluation by inlining.
  In addition, macro will be bad style here, because logging should not
influence the flow of the code.  So here you cannot save.

  If you wan't to save the evaluation of "ackerman(5,5)"
when you disable logging, then you need explicit "if" in your code,
and putting it will also be a good programming style.
This is exactly the case where Ingo Krabbe is right.

  What you do could save is the procedure of creating stack
frame for the call, but very rarely you will need it (unless you
write some embedded application).

  Regards,
   Dima.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux