You are currently offline, waiting for your internet to reconnect

BUG: You may receive compilation errors when you define the _CRTDBG_MAP_ALLOC constant and include the Stdlib.h file in a C++ application in Visual Studio 2005

This article has been archived. It is offered "as is" and will no longer be updated.
Symptoms
Consider the following scenario:
  • You create a C++ application in Microsoft Visual Studio 2005.
  • You define the _CRTDBG_MAP_ALLOC constant.
  • You include the following header files:
    • Malloc.h
    • Crtdbg.h
    • Stdlib.h
  • You include the Crtdbg.h file before you include the Stdlib.h file.
For example, assume that the C++ application contains the following code.
#define _CRTDBG_MAP_ALLOC#include <malloc.h>#include <crtdbg.h>#include <stdlib.h>
In this example, when you compile the C++ application, you receive the following compiler error messages:
error C2059: syntax error : 'constant'
error C2733: second C linkage of overloaded function '_dupenv_s_dbg' not allowed
Workaround
To work around this problem, follow these steps:
  1. Start Visual Studio 2005.
  2. On the File menu, point to Open, and then click Project/Solution.
  3. Locate the project or the solution that you want to open, and then click Open.
  4. Copy and paste the following code in the Code window. The code should be pasted immediately before the #include <stdlib.h> statement.
    #pragma push_macro("_dupenv_s")#pragma push_macro("_wdupenv_s")#undef _dupenv_s#undef _wdupenv_s
  5. Copy and paste the following code in the Code window. The code should be pasted immediately after the #include <stdlib.h> statement.
    #pragma pop_macro("_dupenv_s")#pragma pop_macro("_wdupenv_s")
  6. On the Build menu, click Build Solution.
The code should resemble the following code sample.
#define _CRTDBG_MAP_ALLOC#include <malloc.h>#include <crtdbg.h>#pragma push_macro("_dupenv_s")#pragma push_macro("_wdupenv_s")#undef _dupenv_s#undef _wdupenv_s#include <stdlib.h>#pragma pop_macro("_dupenv_s")#pragma pop_macro("_wdupenv_s")
Status
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.
More information

Steps to reproduce the behavior

  1. Start Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. Under Project types, click Visual C++. If you cannot see the Visual C++ project type, expand Other Languages, and then click Visual C++.
  4. Under Templates, click Win32 Console Application.
  5. Type a project name, and then click OK.
  6. Click Finish.
  7. Copy the following code into the code window.
    #define _CRTDBG_MAP_ALLOC#include <malloc.h>#include <crtdbg.h>#include <stdlib.h>
    Note The previous code should be copied after the #include "stdafx.h" statement and before the int _tmain(int argc, _TCHAR* argv[]) statement.
  8. On the Build menu, click Build Solution. Notice that you receive the compilation error messages that are mentioned in the "Symptoms" section.
Properties

Article ID: 922317 - Last Review: 01/16/2015 16:48:27 - Revision: 2.0

Microsoft Visual Studio 2005 Standard Edition, Microsoft Visual Studio 2005 Professional Edition

  • kbnosurvey kbarchive kbcode kbtshoot KB922317
Feedback