maximus maximus - 1 year ago 99
C++ Question

stackoverflow error at the beginning of the program in function main

I made a program, I want to debug it (or run) and before the first operator in function main it breaks with a message: Unhandled exception at 0x0020f677 in name.exe: Stack overflow.
Why is this happening and how to resolve the problem?
Visual C++ 2010, Win32 console application.

Debugger shows me the asm code at chkstk.asm.

What is important to analyse in order to solve this problem? Something added in header files is causing this problem?

Answer Source

If you decleared a fixed size array and if its size is too much, you may have this error.

int fixedarray[1000000000];

Try to decrease the length or create it on the heap.

int * array = new int[1000000000];

Do not forget to delete it later.

delete[] array;

But it is better to use std::vector instead of pointers even in a C function,

int Old_C_Func(int * ptrs, unsigned len_);
std::vector<int> intvec(1000000000);
int * intptr = &intvec[0];
int result = Old_C_Func(intptr,intvec.size());

assuming 32bit compilation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download