NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

/RTC (Run-time error checks)

/RTC1
/RTCs
/RTCc
/RTCu

Run-time error checks is a way for you to find problems in your running code; see Run-Time Error Checks for a full description of this feature. The run-time error checks feature is enabled and disabled by the /RTC group of compiler options and the runtime_checks pragma.

Note   If you compile your program at the command line using any of the /RTC compiler options, any pragma optimize instructions in your code will silently fail. This is because run-time error checks are not valid in a release (optimized) build.
Options Description
/RTC1 Equivalent of /RTCsu.
/RTCs Enables stack frame run-time error checking,
  • Initialization of local variables to a non-zero value. This helps identify bugs that do not appear when running in debug mode. It is more likely that variables on the stack will not be initialized to zero in release mode than debug mode because of optimizations like stack packing, which allows stack cells to be shared by non-overlapping variables. It is common for uninitialized variables to be zero in a debug build, but nonzero in release builds.
  • Enables detection of overruns and underruns of local variables such as arrays.

    /RTCs will not detect overruns when accessing memory that results from compiler padding within a structure. Padding could occur by using align, /Zp, pack, or if you order structure elements in such as way as to require the compiler to add padding.

  • Stack pointer verification, which detects stack pointer corruption. Stack pointer corruption can be caused by a calling convention mismatch. Using a function pointer, you call a function in a DLL that is exported as __stdcall but you declare the pointer to the function as __cdecl.
/RTCc Reports when a value is assigned to a smaller data type that results in a data loss. For example, if a value of type short 0x101 is assigned to a variable of type char.
/RTCu Reports when a variable is used without having been initialized. For example, an instuction that generates C4701 may also generate a run-time error under /RTCu. Any instruction that generates C4700 will generate a run-time error under /RTCu.

Note that in the following code fragment:

int a, *b, c;
if ( 1 )
b = &a;
c = a;  // no run-time error with /RTCu

If a variable could have been initialized, it will not be reported at run time by /RTCu.

The following preprocessor directives will be defined when you use the compiler option(s) noted.

Preprocessor directive Compiler option
__MSVC_RUNTIME_CHECKS Any /RTC option or /GZ

As with all compiler options, you can preface the option with either a backslash or a hyphen. For example /RTC or –RTC are equivalent.

See Also

Compiler Options | Setting Compiler Options | RTC sample