Programmatically find maximum static array size in C++

Posted by GuyGreer on Stack Overflow See other posts from Stack Overflow or by GuyGreer
Published on 2012-03-31T05:25:00Z Indexed on 2012/03/31 5:29 UTC
Read the original article Hit count: 134

Filed under:
|
|

I am curious whether it is possible to determine the maximum size that an array can have in C++.

    #include <iostream>

    using namespace std;

    #define MAX 2000000

    int main()
    {
      long array[MAX];
      cout << "Message" << endl;
      return 0;
    }

This compiles just fine, but then segfaults as soon as I run it (even though array isn't actually referenced). I know it's the array size too because if I change it to 1000000 it runs just fine.

So, is there some define somewhere or some way of having #define MAX MAX_ALLOWED_ARRAY_SIZE_FOR_MY_MACHINE_DEFINED_SOMEWHERE_FOR_ME?

I don't actually need this for anything, this question is for curiosity's sake.

© Stack Overflow or respective owner

Related posts about c++

Related posts about c