Skip to content

Latest commit

 

History

History
78 lines (60 loc) · 3.09 KB

File metadata and controls

78 lines (60 loc) · 3.09 KB
title Use Native Run-Time Checks
description Use native run-time checks in Visual Studio to catch common run-time errors, such as stack pointer corruption, overruns of local arrays, and stack corruption.
ms.date 10/24/2023
ms.topic how-to
f1_keywords
c.runtime.errorchecks
dev_langs
CSharp
VB
FSharp
C++
JScript
helpviewer_keywords
/RTC compiler option [C++], /O compiler option
run-time checks, native
stack, pointer corruption
stack pointers, corruption
/O compiler option, /RTC option
run-time errors, error checks
O compiler option, /RTC option
debugger, runtime errors
variables [debugger], loss of data
runtime_checks pragma
variables [debugger], catching dependencies on uninitialized local variables
run-time errors, debugging
debugger, native run-time checks
optimized build option
RTC compiler option, /O compiler option
native run-time checks
run-time checks
debugging arrays
stack pointers
arrays [Visual Studio], debugging
author mikejo5000
ms.author mikejo
ms.subservice debug-diagnostics

Use Native Run-Time Checks

In a Visual Studio C++ project, you can use native runtime_checks to catch common run-time errors such as:

  • Stack pointer corruption.

  • Overruns of local arrays.

  • Stack corruption.

  • Dependencies on uninitialized local variables.

  • Loss of data on an assignment to a shorter variable.

    If you use /RTC with an optimized (/O) build, a compiler error results. If you use a runtime_checks pragma in an optimized build, the pragma has no effect.

    When you debug a program that has run-time checks enabled, the default action is for the program to stop and break to the debugger when a run-time error occurs. You can change this default behavior for any run-time check. For more information, see Managing Exceptions with the Debugger.

    The following procedures describe how to enable native run-time checks in a debug build, and how to modify native run-time check behavior.

    Other topics in this section provide information about:

  • Customizing Run-Time Checks with the C Run-Time Library

To enable native run-time checks in a debug build

  • Use the /RTC option and link with the debug version of a C run-time library (/MDd, for example).

    To set the option in Visual Studio, see the Remarks section of the /RTC (Run-time error checks) reference article. Set the value in the Basic Runtime Checks property and not the Smaller Type Check property. The Smaller Type Check property is not recommended.

To modify native run-time check behavior

  • Use the runtime_checks pragma.

Related content