Closed ikehz closed 10 years ago
I talked with Ike about this today; in case anyone else is interested here's what we came up with.
Since A
and B
are both represented in the generated code as the address of A[0]
and B[0]
, it's easy to generate code to do the assignment. The question in my mind is less "is this possible", and more "does this make sense". I'm of the opinion that it does, especially in this context:
int f(int A[]) {
return A[0];
}
void main(void) {
int B[4];
write(f(B));
writeln();
}
Here the call to f
binds the value of B
to the name A
, which is something like an assignment. The code generated should certainly be the same.
Beyond that, there's the cheap explanation of "Bob never told us we can't".
I talked with Bob about this today, and he said we should not allow assignments to arrays. The real issue here is global arrays:
int A[10];
void main(void) {
int B[5];
A = B;
}
What does A = B
mean in this case? Are we copying data? We can't change the pointer to A
, because A
is a global variable.
So, say I've got the following code:
Allowed? Not allowed? It's definitely syntactically correct, and it's type-correct. Are we just giving people what they deserve if they do something like this?