I have a macro with varargs that auto injects some arguments, like the first below injecting the argument "__FNAME__
":
#ifdef VERBOSE
#define logdbg(format, ...) debugff(__FNAME__, format, ##__VA_ARGS__)
#elif defined(NORMAL)
#define logdbg(format, ...) debugf(format, ##__VA_ARGS__)
#else
#define logdbg(format, ...) /* debud off */
#endif
But I need to keep this macro working with compilers without MACRO VARIADIC support (in SCO Unix and AIX 4.3 Copmiler v3).
In these environments I have now:
#ifdef VERBOSE
#define logdbg debugff(__FNAME__, format, ##__VA_ARGS__)
#elif defined(NORMAL)
#define logdbg debugf
#else
#define logdbg if(1);else debugf
#endif
These compilers didn't accepted the comment in the last macro definition, and I get the if(1);else blablabla
that works fine from https://stackoverflow.com/a/687412/926064
But I need yet a solution to the first case, where an argument is "injected" by macro.
Some workaround to do that ?
EDIT:
As it isn't a software with multithread support, I'm thinking to change the debug 'framework' to inject the arguments using side functions to set values in 'context' variables (global, static, etc):
#define logdbg pass_args(__FNAME__); debugf
More possibles workarounds ?
Assuming it is impossible to use a different compiler (which seems a dubious requirement, but let's put that aside), for certain, you will need a different function for
logdbg
to expand into. Probably, that function would take the__FNAME__
argument from another source, like a global variable.Where
vdebugff
is likedebugff
except it takes ava_list
.If thread safety is required, use thread specific storage instead of a common global.