|
|
|
|
|
by AntonErtl
3757 days ago
|
|
I would be pretty miffed if I wrote a, say, Pascal compilers with array bounds checks, and the compiler "optimized" the checks away just because accessing a[i] would be undefined behaviour. OTOH, in a loop like for (i=0; i<16; i++) {
if (i>=0 && i<16)
do something with a[i]
else
report an error; you can certainly optimize the if to if(1). That's an optimization*. |
|
For your example, the Pascal code (at least, I hope this is Pascal; it has been a while since I wrote any):
is equivalent to the C code: A good Pascal compiler, like a good C compiler, would optimise away that second boundary check and the call to RuntimeAbort. Neither compiler is allowed to optimise away the first check.