3 ms·
I think there is some major misunderstanding here. The point the OP was making is that a Sufficiently Smart Compiler should be able tell if a class is a refere
by tsimionescu 2mo ago
I think there is some major misunderstanding here.
The point the OP was making is that a Sufficiently Smart Compiler should be able tell if a class is a reference class (and must be allocated on the heap and referenced by pointer) or a value class (that can be copied around and stored in-line in arrays or other classes).
Specifically, a class can only be a Value Class if two instances of this class are never compared using reference comparison, ==. If the program never uses this operation on two instances of this class, that means that the program would never be affected if copies are passed around instead of the original object being referenced around.
The GP was pointing out that this verification is not actually feasible, as it requires access to the entire source of the entire program, it can't be decided locally.