I’m trying to use a preprocessor directive in a macro? Can/how can this accomplished?
#define HTTP_REQUEST_RETURN_ERROR(error) *errCode = error;
#ifdef DEBUG
LeaveCriticalSection(&debugOutputLock);
#endif
return NULL
Thanks in advance,
Jori.
You can also, of course, define the macro twice, with different definitions:
That makes sure to avoid the (trivially optimizable) run-time
ifthat xdazz used. It also wraps the macro bodies in the typicaldo ... while, to make it look like a statement.UPDATE: To clarify, multi-statement macros in C are often wrapped (in the macro definition) in a
do ... while(0)loop, since that makes the entire text into a single statement. This lets the usage of the macro work well with scopes and semicolons.For instance, consider this:
Without the
do ... while(0), the above would be a syntax error since there would be multiple statements between theifand theelse. Just adding braces to the macro expansion isn’t very clean, since the desirable statement-like usage like the above would result in expansion ofwhich is not very clean, braces following a code scope are not typically followed by a semicolon.