If this is for βarbitraryβ debugging code (as opposed to strict logging), then one rough option is simple #if / #endif .
#if defined(DEBUG) | defined(_DEBUG) #define DBG_ONLY #endif ... #ifdef DBG_ONLY
This is definitely uglier than @perreal's solution, but it avoids any problems associated with defining the scope, and works in all variants of the language (and any other problems that we have not thought about!).
It is also true that this is conditional code, and therefore has the ability to get bad due to synchronization (because it is not always checked by the compiler). But this also applies to the macro solution.
There is another advantage; in a decent IDE (like Eclipse CDT), your debugging code will be highlighted differently.
source share