views:

100

answers:

4
+14  A: 

This should be trivial to verify for yourself by inspecting the resulting binary.

I would say "no", since the expression totally goes away, the compiler will never see the string (it's removed by the preprocessor's macro expansion).

unwind
This is correct. And writing a program to verify it took me all of 30 seconds.
anon
sbi
@sbi: I didn't, I'll gladly admit. I do think that the logic I use in my answer is sound; the preprocessor macro must work like defined, i.e. the string literal disappears from the source. Feel free to quote standards if that's wrong, I'd be happy to know.
unwind
@unwind: I'm not disputing what you say, I'm just disputing that one can come to the same conclusion by testing with any one compiler/std lib combination.
sbi
+3  A: 

Since the preprocessor runs before the compiler, the line will not even exist when the compiler runs. So the answer is no, it does not use any memory at all.

Gorpik
+3  A: 

No, it will not be in the binary. It will not even be compiled - the preprocessor will expand it into an empty string prior to the compilation, so the compiler will not even see it.

sharptooth
+1  A: 

No. The preprocessor is executed prior to compilation, and so the code will never even be seen. I would like to add, though, that if you are interested in adding logging to your C++ application, you might want to use the Log4Cxx library. It uses similar macros which you can completely elide from your application, but when logging is enabled, it supports several different levels of logging (based on importance/severity) as well as multiple different "appenders" to which to send logging output (e.g. syslog, console, files, network I/O, etc.).

The full API documentation may be found at Log4Cxx API docs. Also, if you have any Java developers on board who have used Log4J, they should feel right at home with Log4Cxx (and convince you to use it).

Michael Aaron Safyan