help-gplusplus
[Top][All Lists]
Advanced

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

Re: Can g++ optimize empty function?


From: Bernd Strieder
Subject: Re: Can g++ optimize empty function?
Date: Thu, 07 Dec 2006 18:54:44 +0100
User-agent: KNode/0.10.1

Hello,

Paulo Matos wrote:

> Can g++ optimize an (almost) empty function such as
> ostream& foo(ostream& o) { return o; }

When inlining, surely.

You might include some simple inline definition of the function in its
header file depending on the DEBUG macro.

// debug.h

void foo();
#ifndef DEBUG
inline ostream& foo(ostream& o) { return o; }
#endif

//debug.cc

#ifdef DEBUG
ostream& foo(ostream& o)
{

....

}
#endif

> Problem is I'm strugling to find a way to insert debugging info
> without messing around with Macros too much.


Sometimes it might be helpful to have the logging functions available
even in release mode, just the calls should be neutralized. Then you
could define an simple inline function in release mode, and an inline
function calling the actual code under another name.

There are libraries around to help with logging, maybe you could use one
of them for the dirty work.

Bernd Strieder



reply via email to

[Prev in Thread] Current Thread [Next in Thread]