I want to simply be able to use the macro name without enclosing it in #ifdef-#endif each time. How can I enclose the macro definition itself in a #ifdef-#endif?
Here's my example:
Expand|Select|Wrap|Line Numbers
- #define FAULT
- { \
- if (test.exists()) { \
- return error( "Aborting" ); \
- } \
- } \
Expand|Select|Wrap|Line Numbers
- cout << "Some valid code";
- FAULT
- cout << "Some more valid code";
Most importantly- I want to be able to do this without changing all instances of FAULT as follows:
Expand|Select|Wrap|Line Numbers
- cout << "Some valid code";
- #ifdef TESTME
- FAULT
- #endif
- cout << "Some more valid code";
Here's what I already tried that didn't work:
1) Enclosing the macro itself within #ifdef-#endif
This causes the compiler to complain when it encounters instances of 'FAULT' in the code (since the macro definition no longer exists).
Expand|Select|Wrap|Line Numbers
- #ifdef TESTME
- #define FAULT
- { \
- if (test.exists()) { \
- return error( "Aborting" ); \
- } \
- } \
- #endif
Expand|Select|Wrap|Line Numbers
- #ifdef TESTME
- #define FAULT
- { \
- if (test.exists()) { \
- return error( "Aborting" ); \
- } \
- } \
- #else
- #endif
Expand|Select|Wrap|Line Numbers
- #define FAULT
- { \
- #ifdef TESTME \
- if (test.exists()) { \
- return error( "Aborting" ); \
- } \
- #endif \
- } \
I'll really appreciate any other ideas!