You can try the following:
#define IF_TRACE_ENABLED(level) do { if(IsTraceEnabled(level)) { #define END_TRACE_ENABLED } } while(0);
I donβt think there is a way to βprovideβ good syntax just from the first line of the macro. You will need to use two.
EDIT
I added an extra macro inside the macro to avoid any ambiguity.
In response to a comment, this macro is intended to be used as follows:
IF_TRACE_ENABLED(LEVEL1) printf("Trace\n"); END_TRACE_ENABLED
Not as a statement. For the record, I believe this is an abuse of the preprocessor, and no one should do this at all. What's wrong, just by writing it, enclosed in brackets with #ifdef DEBUG if necessary.
ptomato
source share