This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: selective function call


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]