Detecting that the stack is full in C/C++

Posted by Martin Kristiansen on Stack Overflow See other posts from Stack Overflow or by Martin Kristiansen
Published on 2012-06-18T09:12:23Z Indexed on 2012/06/18 9:16 UTC
Read the original article Hit count: 339

Filed under:
|
|
|

When writing C++ code I've learned that using the stack to store memory is a good idea.

But recently I ran into a problem:

I had an experiment that had code that looked like this:

void fun(unsigned int N) {
    float data_1[N*N];
    float data_2[N*N];

    /* Do magic */
}

The code exploted with a seqmentation fault at random, and I had no idea why.

It turned out that problem was that I was trying to store things that were to big on my stack, is there a way of detecting this? Or at least detecting that it has gone wrong?

© Stack Overflow or respective owner

Related posts about c++

Related posts about c