|
|
|
|
|
by msebor
2250 days ago
|
|
This is a good example. Let me flesh it out a bit more to illustrate a specific instance of this problem: int a[2][2];
int f (int i, int j)
{
int t = a[1][j];
a[0][i] = 0; // cannot change a[1]
return a[1][j] - t; // can be folded to zero
}
The language says that elements of the matrix a must only be accessed by indices that are valid for each bound, so compilers can and some do optimize code based on that requirement (see https://godbolt.org/z/spSF8e).But when a program breaks that requirement (say, by calling f(2, 0)) the function will likely return an unexpected value. |
|