So it's well known that C does not have any array bounds checking when accessing memory. Nowadays, if you call myArray[7]
when you initialised it as int myArray[3]
, your program will get a segfault and crash thanks to protected memory.
Now, if you have an argument in a function such as myFunc(int *yourArray)
, but you know you need at least 8 slots in the array, is it possible to check if myArray[7]
is illegal beforehand in order to throw a custom error:
"Sorry, yourArray is too small for this function. We need 8 ints of space."
rather than
"Segmentation fault."
std::array
– Darkhogg Aug 20 at 0:56