0

I compile the next code, and compile it succesfully:

#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
    // cast the first parameter to int and assing to variable
    int size_of_array ;
    istringstream string_to_int(argv[1]);
    string_to_int >> size_of_array;

    std::pair<int, int> arr1[5021410];
    cout << "arr1 declared." << endl;
    std::pair<int, int> arr2[size_of_array];
    cout << "arr2 declared." << endl;

    return EXIT_SUCCESS;
}

I compile it with the next command:

g++ -o testing_error.bin testing_error.cpp -O3 -Wall -g

(testing_error.cpp is the code showing above, obviously).

If I exec the script, but I get a segmentation fault erro:

$ ./testing_error.bin 5021410
arr1 declared.
[1]    10753 segmentation fault (core dumped)  ./testing_error.bin 5021410

I'm not figure out where is my mistake. Any idea?

Tuxman
  • 378
  • 4
  • 13
  • Use of `std::pair arr1[5021410];` requires large amount space in stack. It appears that your platform doesn't have support for that. There are quite a few posts at SO that address the issue. – R Sahu Oct 28 '19 at 20:00
  • @RSahu, that line work fine (show in the output, the string "arr1 declared" is showed fine). – Tuxman Oct 28 '19 at 23:28

0 Answers0