Reputation: 20698
I wanted to try out a more complex example of allocating memory with new in an object and allocating further inside it, but needed to know for sure when a stackoverflow will happen. So decided to try this example. I called the foo()
function from main()
and expected it to give a stackoverflow error. It didn't. In foo, I increased the array size by a few more zeros and added 40 more such array declarations in foo. Still didn't crash.
Am using gcc version 4.4.2 20091027 (Red Hat 4.4.2-7) (GCC). Shouldn't a stack allocation of approx more than 1MB give a stackoverflow error?
void foo()
{
double x[100000000];
double x1[100000000];
double x2[100000000];
double x3[100000000];
double x4[100000000];
//...and many more
}
int main()
{
foo();
}
Compiled as gcc -o test test.c
Upvotes: 2
Views: 101
Reputation: 16789
Make foo call itself recursively, and have some counter increment with each call. You'll get your fault soon enough.
Upvotes: 5