Originally Posted by
osyrez
I had assumed that creating an array of such a large size would cause some kind of an error on most systems but wasn't sure what to do about it.
Creating an array of that size isn't only an error for most systems, it's an error for a compiler. You simply can't have an array of that size.
Code:
const unsigned int USIGN_MAX = (unsigned int)-1; // The largest unsigned value
const signed int SIGN_MAX = USIGN_MAX / 2; // The largest signed value
int main() {
int foo[SIGN_MAX] = { 0 };
return 0;
}
On my computer, SIGN_MAX was 2147483647. Which would make this a 32 bit integer. Now, if you do the math (We'll make it 2147483648 to remain in integers).
Code:
2147483648
times 4 bytes
equals 8589934592 bytes
divided by 1024
equals 8388608 kilobytes
divided by 1024
equals 8182 megabytes
divided by 1024
equals 8 gigabytes of memory
You can see why this is a problem. Your compile may let you get away with this with a char, but if you plan on initializing it, good luck getting it to run.