1.5 Stack Checking on Entry

For certain library routines, the compiler performs stack checking on entry. (The “stack” is a memory area used for temporary storage.) Upon entry to such a routine, the stack is checked to determine if it has enough room for the local variables used by that routine. If it does, space is allocated by adjusting the stack pointer. Otherwise, a “stack overflow” run-time error occurs. If stack checking is disabled, the compiler assumes there is enough stack space; if there is not, you might overwrite memory locations in the data segment and receive no warning—unpredictable program behavior may result.

Typically, stack checking is enabled only for functions with large local-variable requirements (more than about 150 bytes), since there is enough free space between the stack and data segments to handle functions with smaller requirements. If the function is called many times, stack checking slows execution slightly.

Stack checking is enabled for the following library functions:

_execvp_execvpefprintffscanfprintfscanf_spawnvp_spawnvpesprintfsscanfsystemvprintf_write

You can enable or disable stack checking with the /Gs and /Ge compiler options (see Chapter 13 of Environment and Tools) or the check_stack pragma (see Chapter 7 of the C Language Reference). Both books are in the Microsoft C/C++ version 7.0 documentation set.