Problems with stack size

I have a function call which has the address of an array as one of its parameters.

The called function is declaring the array as
float array[1000000];

The program throws a segmentation fault when this function call happens. Assuming it to be a problem with the stack size, I compiled the file with this option -stack=100000000,20000000. It now executes fine.

I set the environment variable PGI_STACK_USAGE to check the stack size. I got message:
thread 0 stack: max 30708KB, used 4232KB.

If this has something to do with stack size. Then I had set ulimit -stack unlimited in my shell, but then why was I getting this segementation fault?

Hi Sudeep Mohan,

If this has something to do with stack size. Then I had set ulimit -stack unlimited in my shell, but then why was I getting this segementation fault?

Given that you’re using the “-stack” flag, I’m assuming that you’re using Windows? In this case, the stack size gets set by the MS linker at link time with the default of 1MB. Since your program uses a little over 4MB of stack, then yes the original problem is most likely due to a stack overflow.

Hope this helps,
Mat

Hi,
Thankyou for your reply.

I am running this program on interix, which is a unix environment subsystem for MS Windows.
I had also set the stack size to unlimited by using the ulimit command.

So even with this environment set will the stack size allocated to the programs be 1MB?
Or does it has to do anything with the scenario that Interix is on the windows and that windows kernel is providing the services for unix?

Hi,
To add some more info.

I am actually migrating this program from solaris to interix, and the very same code seems to work fine in solaris. so any exact reason as to why it behaves this way in interix?