I am curious if it is possible to determine the maximum size 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 (although the array is not actually referenced). I know that this is the size of the array, because if I change it to 1,000,000, it will work fine.
So, is there some way somewhere or somehow to have #define MAX MAX_ALLOWED_ARRAY_SIZE_FOR_MY_MACHINE_DEFINED_SOMEWHERE_FOR_ME ?
In fact, I do not need this, it is a question for the sake of curiosity.
c ++ memory
SirGuy
source share