But I only want the LOG macro to work if USE_LOG is defined... in other words, if USE_LOG isn't defined, the LOG macro won't do anything. I'm trying to write the macro for this but I can't get it right:
warning C4067: unexpected tokens following preprocessor directive - expected a newline c:\...\logger.h
Also I'm just not sure if it will do what I think it will do... if USE_LOG isn't defined and the call "disappears" everywhere it is used in code, will it leave behind semicolons everywhere? If so, is this a bad thing? Will the compiler interpret these as statements and spend time processing them?
That's a very good question.
I know just a little to say that parameterized macro expands its argument as text,
which in C++ could be anything from a number to invalid expression depending on where it's used. But then again, I don't know what it would really expands to.
Quite simple: The preprocessor will replace ``LOG("Called f().")´´ with an empty string, thus your code will look like:
Code:
void f()
{
;
}
to the compiler. The single semicolon will not translate to any code on compilation.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Oh, and btw, you might want to lookup the __func__ macro which will automatically expand to the function name.
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf
Premature optimization is the root of all evil --Donald E. Knuth
Bookmarks