BUG: You receive a run-time exception error message when you run the debug build of your application with the /RTCs compiler option enabled

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

On This Page


When you run the debug build of your application with the /RTCs compiler option enabled, you may receive the following exception error message:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.
You receive this error message when the following conditions are true:
  • You call a function that does not use the __cdecl modifier.
  • The function contains parameters that are larger than 64 kilobytes (KB).
  • You compile your application in the Debug mode and with the /RTCs compiler option enabled.


When you pass a parameter that is 64 KB or larger to a function that does not use the __cdecl modifier, the compiler generates incorrect code. When the function that is called tries to return control to the calling function, the compiler triggers the error that is mentioned in the "Symptoms" section. The compiler generates a 16-bit immediate return (RET) that has an operand that is limited to 64 KB. If the parameters that are passed to the function are larger than 64 KB, the stack becomes corrupted when the function returns.


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.


Steps to reproduce the behavior

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual C++ Projects, and then click Win32 Project under Templates.
  4. In the Name box, type MyProject, and then click OK. The Win32 Application Wizard - MyProject dialog box appears.
  5. On the Welcome to the Win32 Application Wizard page, click Application Settings. The Application Settings page appears.
  6. Click Console application, and then click Finish.
  7. In Solution Explorer, right-click MyProject.cpp, and then click Open.
  8. Locate the following code in the MyProject.cpp file:
    #include "stdafx.h"
  9. Add the following code after the code that you located in step 8:
    struct MyStruct 
            unsigned char MyData[65535];
    void __stdcall MyFunc(MyStruct m_MyStruct) 
            m_MyStruct.MyData[0] = 'G';
  10. Replace the existing code in the _tmain procedure with the following code:
    MyStruct m_Temp;
    return 0;
  11. In Solution Explorer, right-click MyProject, and then click Properties. The MyProject Property Pages dialog box appears.
  12. In the left pane of the MyProject Property Pages dialog box, click Configuration Properties.
  13. Under Configuration Properties, click C/C++, and then click Code Generation.
  14. Set the Basic Runtime Checks property to Stack Frames (/RTCs).
  15. Click Configuration Manager. The Configuration Manager dialog box appears.
  16. In the Active Solution Configuration list, click Debug, and then click Close.
  17. In the MyProject Property Pages dialog box, click OK.
  18. On the File menu, click Save All to save all the files.
  19. On the Build menu, click Build Solution to build the application.
  20. On the Debug menu, click Start to run the application.


For more information, visit the following Microsoft Developer Network (MSDN) Web sites:
/RTC (Run-time error checks)


Article ID: 822039 - Last Review: June 1, 2007 - Revision: 1.3
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
kbcompiler kbdebug kberrmsg kbtshoot kbbug KB822039

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