Well this is a very interesting read. My main reason for posting this question was in many high-level languages, if you declare an array as having a certain number of elements, and then you mistakenly try to read or write an element past that point, the program will throw an exception. It makes debugging nice and easy.
So I was wondering if the above exception was caused by (1) the compiler itself adding these checks into the code, or (2) whether it was just a general error thrown by the OS, so as long as you trap it you'll be fine.
^ And my conclusion from the above is that #2 is false and not to be relied upon to avoid data corruption... because the OS will only throw said exception if you try to read/write to memory outside your entire program's allocation (it doesn't care if you read beyond the max size of local array variable within your program's allocation).
^ And as for #1, I am still unsure. Does the compiler add these checks in? So for instance, if all you write is (pseudo-code):
// Assume you have an array dimensioned called myArray with 4 elements (indicies 0-3);
myArray[4] = 9000;
Does the compiler automatically add in checks like this?
Compare 4 to count of myArray;
If 4 is less than 0 or greater than 3, thrown an error;
Otherwise, 4 is within bounds, so let myArray[4] = 9000;
Thanks