
Chris Uzdavinis wrote:
Rene Rivera <grafik.list@redshift-software.com> writes:
It's possible without macros for some compilers using careful template instaciations.
For example the very simple logger I wrote uses syntax like so (and yes I prefer printf formatting :-)...
log<RevisionLog>::trace( "RevisionControl::commit_; wait for ticket #%d",ticket);
Because the formatting is done by the trace call, and the trace call is empty (and inlined) when the log is disabled, no formatting takes place. Something similar can be done regardless of what the formatting object is by having a specialization that does nothing.
That does not eliminiate any overhead that may exist due to evaluating the function arguments prior to making the call,
Compilers tend to eliminate unused code very effectively. And for most logging use cases you are only using already existing bindings (in the compiler SSA sense) as you are reflecting the state of your program. So no new code is getting generated.
nor any potential side effects of those expressions.
If you are in a situation where you have side effects of consequence, or any side effect for that matter, in you logging statements you have considerably more to worry about. I'd say a redesign of your code would be in order at that point.
Personally, having debugging log statements completely disappear from the source code in a release build is more comforting, even if it involves a macro.
It's comforting in an old style sense :-) But I prefer to limit macro use as it interferes with debugging. -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq