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]

selective function call


Hi all,

I am trying to write a smart logger that can be activated/deactivated at
run-time. I have a print function for the logger that gets va_list:

	void tLogger::print(const char *format, ...) {
		if (!is_activated())
			return;
		va_list marker;
		va_start(marker, format);
		etc. etc.


Trouble is with performance. When I call the print function while the
logger is not activated arguments are still passed to the function. This
is very time-consuming.

Is there a way to avoid passing unnecessarily extra arguments?

Obviously I can write my code as:

 	if (logger->is_activated())
		logger->print("%d\n", ackerman(5,5));

But this is very tiring.
I created a MACRO

	#define LOG if (logger->is_activated()) logger->print

and use it:
	LOG("%d\n", ackerman(5,5));

but this seems to me a very fragile solution.

I tried an inline function (hoping for the optimizer would kick in) but
it was no good.

Is there an more elegant solution for this?

Hayim.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]