The question came to mind by looking at the memory leak detection mechanism in VS. There the following boilerplate code is needed :
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
but replacing this code with DETECT_MLEAKS
:
#define DETECT_MLEAKS\
#define _CRTDBG_MAP_ALLOC\
#include <stdlib.h>\
#include <crtdbg.h>\
can't be done.
Are there any workarounds - suggestions ?
//#define DETECT_MLEAKS //Uncomment to detect mem-leaks
#ifdef DETECT_MLEAKS
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#endif
Is how I typically do such things.
In the standard C language, macros cannot generate preprocessing directives. For instance in the ISO 9899:1999 standard:
6.10.3.4 Rescanning and further replacement
[ ... ]
The resulting completely macro-replaced preprocessing token sequence is not processed as a preprocessing directive even if it resembles one, [ ... ]
(This "even if it resembles one" remark is completely superfluous because, of course, no syntax is ever treated as a preprocessing directive if it does not resemble one! Yet, the words stick in your mind for years. I just located the quote's section by searching the document for the string "resembles one".)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With