Microsoft KB Archive/922317

= 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 ID: 922317

Article Last Modified on 7/21/2006

-

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

-





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. In this example, when you compile the C++ application, you receive the following compiler error messages:
 * 1) define _CRTDBG_MAP_ALLOC
 * 2) include 
 * 3) include 
 * 4) include 

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:  Start Visual Studio 2005. On the File menu, point to Open, and then click Project/Solution. Locate the project or the solution that you want to open, and then click Open.  Copy and paste the following code in the Code window. The code should be pasted immediately before the #include  statement.  Copy and paste the following code in the Code window. The code should be pasted immediately after the #include <stdlib.h> statement. On the Build menu, click Build Solution.</li></ol>
 * 1) pragma push_macro(&quot;_dupenv_s&quot;)
 * 2) pragma push_macro(&quot;_wdupenv_s&quot;)
 * 3) undef _dupenv_s
 * 4) undef _wdupenv_s </li>
 * 1) pragma pop_macro(&quot;_dupenv_s&quot;)
 * 2) pragma pop_macro(&quot;_wdupenv_s&quot;) </li>

The code should resemble the following code sample.
 * 1) define _CRTDBG_MAP_ALLOC
 * 2) include <malloc.h>
 * 3) include <crtdbg.h>


 * 1) pragma push_macro(&quot;_dupenv_s&quot;)
 * 2) pragma push_macro(&quot;_wdupenv_s&quot;)
 * 3) undef _dupenv_s
 * 4) undef _wdupenv_s
 * 5) include <stdlib.h>
 * 6) pragma pop_macro(&quot;_dupenv_s&quot;)
 * 7) pragma pop_macro(&quot;_wdupenv_s&quot;)

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.

<div class="moreinformation_section">

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

Keywords: kbtshoot kbbug kbcode KB922317

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.