Re: #defining a comment
* Phlip:
Erik WikstrFm wrote:
#ifdef NDEBUG
#define QTRACE //
#else
#define QTRACE qDebug()
#endif
I'm not really sure since I seldom use macros but I think that the // is
treated as a comment by the preprocessor. Try #define QTRACE \/\/.
I accidentally did that once. (The comment addressed the macro, not
deliberately the rest of the line.)
IIRC VC++ did not erase the following text, and GNU g++ did.
I don't care what the Standard sez - don't do it.
Andr9 is advised to do this:
#define QTRACE(x) qDebug() << x_
QTRACE("Foi lido o valor" << *it);
Were it not for modern compilers' annoying habit of spewing out warnings
for constant boolean expressions & dead code, an alternative could be
#ifdef NDEBUG
bool const nDebug = true;
#else
bool const nDebug = false;
#endif
...
nDebug || qDebug() << "Foi lido o valor" << *it;
Possibly the sillywarnings can be circumvented by doing instead
#ifdef NDEBUG
static bool nDbgKludge_BF767D92_5347_4205_8A67_55651CD79C77_ = true;
#else
static bool nDbgKludge_BF767D92_5347_4205_8A67_55651CD79C77_ = false;
#endif
bool const& nDebug = nDbgKludge_BF767D92_5347_4205_8A67_55651CD79C77_;
...
nDebug || qDebug() << "Foi lido o valor" << *it;
Hah, now that I thunk of it I think I'll try it, perhaps it works... ;-)
It (1) isn't a macro, which is Good, and (2) spells out exactly what the
effect is each place it's used, which is also Good, and (3) the output
expression isn't evaluated (no side-effects) if nDebug, which is both
Good and Bad (Bad because release and debug builds may act differently),
but is the same as with the macro solution.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?