I want to compile code conditionally based on a macro. Basically I have a macro that looks like (Simplified from the real version):
#if DEBUG
#define STA
So you want conditional blocks with their own scope?
Here's a quite readable solution that relies on the compiler to optimize it away:
#define DEBUG 1
if (DEBUG) {
// ...
}
And here is one that is preprocessor-only:
#define DEBUG 1
#ifdef DEBUG
#define IFDEBUG(x) {x}
#else
#define IFDEBUG(x)
#endif
IFDEBUG(
// ...
)
Or manually:
#define DEBUG 1
#ifdef DEBUG
{
// ...
}
#endif