Export (0) Print
Expand All
Expand Minimize

_resetstkoflw

Recovers from stack overflow.

int _resetstkoflw ( void );

Return Value

Nonzero if the function succeeds, zero if it fails.

Remarks

The _resetstkoflw function recovers from a stack overflow condition, enabling a program to continue instead of failing with a fatal exception error. If you don't call _resetstkoflw, there is no guard page after the previous exception and the next time there is a stack overflow there will be no exception at all; the process will simply terminate without warning.

This function should only be called from a __try block.

Requirements

Routine Required header Compatibility
_resetstkoflw <malloc.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// crt_resetstkoflw.c

/* Launch program with and without arguments to observe  */
/* the difference made by calling _resetstkoflw()        */          

#include <malloc.h>
#include <stdio.h>
#include <windows.h>

void recursive(int recure)
{
   _alloca(2000);
   if (recure)
      recursive(recure);
}

int main(int ac)
{
   int i = 0;
   int recure = 1, result = 0;

   for (i = 0 ; i < 10 ; i++)
   {
      printf("loop #%d\n", i + 1);
      __try
      {
         recursive(recure);

      }

      __except(GetExceptionCode() == STATUS_STACK_OVERFLOW)
      {
         if (ac >= 2)
         {
            puts("resetting stack overflow");
            result = _resetstkoflw();
         }
      }

      if (!result)
         return 3;
   }

   return 0;
}

Sample Output

With no program arguments:

loop #1

With program arguments:

loop #1
resetting stack overflow
loop #2
resetting stack overflow
loop #3
resetting stack overflow
loop #4
resetting stack overflow
loop #5
resetting stack overflow
loop #6
resetting stack overflow
loop #7
resetting stack overflow
loop #8
resetting stack overflow
loop #9
resetting stack overflow
loop #10
resetting stack overflow
Show:
© 2014 Microsoft