Segmentation fault when using large numbers in native array

时间:2017-04-06 16:52:12

标签: c++ algorithm sorting

I have a problem with this simple array assignment. When I use lower numbers such as 100, 1000, etc. the program works well. But if I use a larger number like 1000000 the program crashes at the following line :

int list[listLength];

and I don't know why.

The following example works well:

int main(int argc, char* argv[]){
   const long long listLength = 1000;
   int list[listLength];

   return 0;
}

But the following example does not work:

int main(int argc, char* argv[]){
    const long long listLength = 1000000;
    int list[listLength];


    return 0;
}

using de gdb debugger, i get the following error message just in the assignment:

error line:

int list[listLength];

error message:

Signal received: SIGSEGV (Segmentation fault) For program algorithms, pid 5.252

iam building it on 64 bits pc (for 32 bits target) with mingw32 using c++11.

Why doesn't the second example work?

0 个答案:

没有答案