I apologize for posting in haste. The OP syntax compiles fine. I am
still a bit puzzled as to why the OP syntax works ( example code
below)
#include <iostream>
#define IDIAG !LogEnabled() ? false : printf
bool LogEnabled() { return false; }
int main() {
IDIAG("this is to be logged\n");
return 0;
}
and not this
#include <iostream>
#define IDIAG false
int main() {
IDIAG("this is to be logged\n");
return 0;
}
$ g++ -o testfalse testfalse.cc
testfalse.cc: In function `int main()':
testfalse.cc:6: error: `false' cannot be used as a function
My understanding of Macro definitions is that it is a inplace
substitution. So that in both examples above the line IDIAG("this is
to be logged\n"); is actually translated to false("this is to be
logged\n");
I guess my understanding is incorrect.. so would greatly appreciate to
be corrected and enlightened,
Thank you for all the replies and your valuable time.
Regards,
--Raghu
pa******@rediffmail.com (Raghuveer Pallikonda) wrote in message news:<81**************************@posting.google. com>...
Hi,
I am trying to stub out debug log messages in my application, if
the logging subsystem is not enabled.. For e.g a invocation
#define LOGMSG !Logger::Enabled() ? false : Logger::LogMsg
so that
LOGMSG("Log Me\n");
will be a NO-OP if the Logger::Enabled() returns false, else the
message will be logged appropriately by the function call to
Logger::LogMsg().
My compilation fails with errors (g++ 3.3 compiler). I have seen
similar macro definition in another working program. Should I be
passing some compile options to g++ compiler to get this working?
#define LOGMSG !Logger::Enabled() ? false : Logger::LogMsg
Thank you in advance for help.
--Raghu