I am working on a project involving a join algorithm (similar to a SQL join, coded in C/C++).
I have tried both arrays and vectors as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
cout << "UINT_MAX = " << UINT_MAX << endl;
cout << max << " is the calculated max" << endl;
vector<bool> exists (max, false);
inFile.open("tempVFile");
exists[5] = false;
cout << "Flag -1" << endl;
exists[292915] = false;
cout << "Flag0" << endl;
exists[292916] = false;
cout << "Flag1" << endl;
exists[292917] = false;
cout << "Flag2" << endl;
|
Above is vectors. Here is the output when compiled and run:
UINT_MAX = 4294967295
4294967295 is the calculated max
Flag -1
Segmentation fault (core dumped)
Below is Arrays.
1 2 3 4 5 6 7 8 9 10
|
bool exists[max];
cout << "UINT_MAX = " << UINT_MAX << endl;
cout << max << " is the calculated max" << endl;
for(unsigned int i = 0; i < max; i++)
{
exists[i] = false;
if (i > 292910)
cout << i << " is done" << endl;
}
cout << "Post read" << endl;
|
And the produced output:
UINT_MAX = 4294967295
4294967295 is the calculated max
292911 is done
292912 is done
292913 is done
292914 is done
292915 is done
Segmentation fault (core dumped)
As seen, both core dump when trying to access a larger index. The gdb symbolic debugger does not tell me much (but I am by no means an expert in using it.)
(gdb) run
UINT_MAX = 4294967295
4294967295 is the calculated max
Flag -1
Program received signal SIGSEGV, Segmentation fault.
0x0805295c in std::_Bit_reference::operator= (this=0x80477c4, __x=false) at stl_bvector.h:87
87 *_M_p &= ~_M_mask;
(gdb) backtrace
#0 0x0805295c in std::_Bit_reference::operator= (this=0x80477c4, __x=false) at stl_bvector.h:87
#1 0x080521b1 in main () at join2.cpp:46
So if anyone could point me in the correct direction on an answer to this (why it occurs and/or how to fix it) I would be very appreciative.
Thanks!!