I had a problem with arrays in a large program and have simplified it down into an example that has almost the same features of my original problem: writing to an array index out of bounds. The basic point is that a segmentation violation is protected against by the interpreter, and ignored by the compiler. When I run the following macro using the interpreter, I get : root [0] .L check_array.C root [1] check_array() Error: Array index out of range ary -> [3] valid upto ary[2] FILE:check_array.C LINE:10 Error: Array index out of range ary -> [4] valid upto ary[2] FILE:check_array.C LINE:10 Error: Array index out of range ary -> [4] valid upto ary[2] FILE:check_array.C LINE:10 (int)0 *** Interpreter error recovered *** However, when I use the compiler I get : root [0] .L check_array.C++ Creating shared library /misc/data06a/ben/3.11.1/./check_array_C.so root [1] check_array() val is -1073785306 In case it is relevant, this was in root 3.01/01. Can any protection be in place against something like this ? Cheers, Ben //--------------------------------------------------- // Here is the example macro: check_array.C //--------------------------------------------------- #include <iostream.h> void check_array () { int ary[3]; int val; // note : that I am accessing illegal memory for (int i=0; i < 5; i++) { ary[i] = i; val += ary[i]; } cout << " val is " << val << endl; }
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:46 MET