Address Confusion
Address Confusion
The following simple program has different meanings in different languages:
function f(x, y, z) {
x = z + 1
y = z + 2
}
As a JavaScript program, it has no effect on anything because x, y, and z are local variables to the function, initialized to be the three values that f was called with. They disappear when f returns.
Interpreted as FORTRAN and called by f(a, b, 7) it changes the value of a to 8, and b to 9. But if you call it with f(a, b, a), it will increase a by 1 and set b to the original value of a plus 3. Worse, if you call it with f(7, b, 7) it might change the “constant” 7 to 8 and set b to 10!
Interpreted as ALGOL it will act like FORTRAN for f(a, b, 7). But called with f(i, b, A[i]) when i=6 and A[i]=7 it will set i to 7, and B to A[7]+2.
Behind these anomalies is the fact that different languages treat the parameters of f sometimes as addresses, sometimes as the contents of the addresses, and (in ALGOL) the symbolic expressions that appear in the call. What a mess!