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

Article translations Article translations
Article ID: 922317 - View products that this article applies to.
Expand all | Collapse all

On This Page

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: July 21, 2006 - Revision: 1.0
APPLIES TO
  • Microsoft Visual Studio 2005 Team System Architect Edition
  • Microsoft Visual Studio 2005 Team System Developer Edition
  • Microsoft Visual Studio 2005 Team Foundation
  • Microsoft Visual Studio 2005 Team System Test Edition
  • Microsoft Visual Studio 2005 Express Edition
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Professional Edition
Keywords: 
kbtshoot kbbug kbcode KB922317

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com