I am trying to identify memleaks in my c++ program. I use Visual Studio 2008.
I have found a few tutorials dealing with identifying memleaks while using new, not malloc, for memory allocation and this is what i have defined on top of my main:
#define __STDC_CONSTANT_MACROS
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
unfortunately I get tons of errors, which you can see here: http://pastebin.com/9ax90VTg
But I think I have found the problem: there is neighter __FILE__ nor __LINE__ defined. When I click “RMB->go to definition” OR “RMB->go to declaration” on __FILE__ or __LINE__ I get:
the symbol '__FILE__' is not defined
and
the symbol '__LINE__ ' is not defined
respectively.
How should I solve this?
The symbols
__FILE__and__LINE__should always be defined, by the compiler. If they aren’t, you must be using some special options to inhibit them.On the other hand, the code you’ve posted cannot be used with the standard library, and so should be avoided. It is not a good solution for finding memory leaks.
EDIT: On rereading your posting: you seem to be counting on the debugger to show you the definitions; it can’t, because they are generated automatically by the compiler, changing during compilation. On the other hand, the errors you are seeing are very compatible with the fact that your macro redefines a keyword, in a way that breaks the standard library code.