Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

EDIT1: 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?

like image 337
maximus Avatar asked Mar 23 '11 06:03

maximus


People also ask

How do I fix stackoverflow error in Java?

Increase Thread Stack Size (-Xss) Increasing the stack size can be useful, for example, when the program involves calling a large number of methods or using lots of local variables. This will set the thread's stack size to 4 mb which should prevent the JVM from throwing a java. lang. StackOverflowError .

What is a stackoverflow error Why does it happen?

A stack overflow is a type of buffer overflow error that occurs when a computer program tries to use more memory space in the call stack than has been allocated to that stack.

Can we catch stackoverflow error?

StackOverflowError is an error which Java doesn't allow to catch, for instance, stack running out of space, as it's one of the most common runtime errors one can encounter.

How do I fix the error in my code stackoverflow?

How can I fix the stack overflow system halted error? Such errors often result from calling a recursive function that never terminates before calling itself again. The cure is to keep track of the depth of recursion and to exit the function before it can call itself again, when that depth of recursion has been reached.


1 Answers

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.

like image 197
ali_bahoo Avatar answered Sep 19 '22 13:09

ali_bahoo