Can I combine macros while writing code for C or C++? If not, why? If yes, how?
I'm interested on how to solve the following (not correct and NOT compiling!!!) idea:
#define FREE(x) if((x)) { \
#ifdef MEM_DEBUG_ \
fprintf(stderr, "free:%p (%s:%d)\n", (x), __FILE__, __LINE__); \
#endif \
free((x)); }
So, what I want to achieve is this:
I want to define the macro FREE
in way that it will include an extra line if I have the MEM_DEBUG
defined.
I know, that for solving this I can have two defines for the FREE
based on MEM_DEBUG
, like:
#ifdef MEM_DEBUG
#define FREE() something
#else
#define FREE() something else
#endif
but I'm just curios if there is another way!