In Visual Studio 2008, there's a nice debug heap coded in file dbgheap.c
. It implements functions such as _CrtDumpMemoryLeaks()
.
I note the file includes extern "C"
directives that don't seem to be allowed by Microsoft's own compiler. Code like:
extern "C" _CRTIMP int __cdecl _CrtDumpMemoryLeaks(
void
)
{
/* only dump leaks when there are in fact leaks */
Simply produces errors if you try to compile it yourself. Obviously there are compiler flags to allow this syntax, but anyone know what the flags are?
In this case, it turns out that while the code is otherwise 100% legal C, except for these extern "C"
qualifiers, it also compiles perfectly with flag /TP
which means, "compile as C++ disregarding the file name."
So, I imagine that's what they did.
I think MSFT just overlooked putting the extern "C"
qualifiers in some sort of conditional compilation dependent on the __cplusplus
flag or something.