We help IT Professionals succeed at work.

#pragma check_stack (off) doesn't work....

ab11 asked
Hi !

I have created the following simple program. I only need to disable
stack verification at the epilog of the function. For this purpose, I
put #pragma check_stack (off) before the body of ThreadFunc1.

#include <windows.h>

#pragma check_stack (off)
int WINAPI ThreadFunc1 () {
 return 0;

void main(){

However, it seems that the putting of #pragma check_stack (off) change
nothing to my code. In both cases (when check_stack exists or not) I
have __chkesp function generated for me. Bellow is the epilog of
ThreadFunc1  :

0040B55B   pop         edi
0040B55C   pop         esi
0040B55D   pop         ebx
0040B55E   add         esp,40h
0040B561   cmp         ebp,esp
0040B563   call        __chkesp (004010e0)
0040B568   mov         esp,ebp
0040B56A   pop         ebp
0040B56B   ret

What do I miss ?

Thanks in Advance !

Watch Question

What are the compiler parameters you use, and what's the compiler type - Borland, Microsoft?


I am using MSVC++ 6.0 SP3
First, I used the default settings for "Command Line" Project. Then, I tried to "play" with /Gs (/Ge) option, but this didn't help me as well.
According to MS documentation,it seems that by specifying #pragma check_stack (off) I should allways get __chkesp omitted...

Vadim, the /GZ compiler flag that is included by default in debug builds apparently overrides the #pragma.

Remove the flag to disable stack probes but be aware that other behaviour is affected as well.

The /GZ option does the following:
- Auto-initialization of local variables
- Function pointer call stack validation
- Call stack validation


Thanks ! It's really great !
It really looks stupid from my side not find this thing by my own, but still it wasn't too intuitive : when you go to check_stack article,  /GZ option isn't mentioned there at all; in addition,the fact that there some chances that my "pragma" maybe overwritten isn't mentioned as well.
So what I had to do is to guess that maybe there are some debug options which overwrite my "pragma" and then check one by one all the debug options...

Next time I will do better :)