#if 0 as a define
Posted
by valerio
on Stack Overflow
See other posts from Stack Overflow
or by valerio
Published on 2010-02-09T21:42:40Z
Indexed on
2010/03/17
17:21 UTC
Read the original article
Hit count: 394
I need a way to define a FLAGS_IF
macro (or equivalent) such that
FLAGS_IF(expression)
<block_of_code>
FLAGS_ENDIF
when compiling in debug (e.g. with a specific compiler switch) compiles to
if (MyFunction(expression))
{
<block_of_code>
}
whereas in release does not result in any instruction, just as it was like this
#if 0
<block_of_code>
#endif
In my ignorance on the matter of c/c++ preprocessors i can't think of any naive way (since #define FLAGS_IF(x) #if 0
does not even compile) of doing this, can you help?
I need a solution that:
- Does not get messed up if
*/
is present inside<block_of_code>
- Is sure to generate 0 instructions in release even inside inline functions at any depth (i guess this excludes
if (false){<block_of_code>}
right?) - Is standard compliant if possible
Thank you
© Stack Overflow or respective owner