On 20 Nov 2002 at 15:50, Prof. A Olowofoyeku (The African Chief) wrote:
If you write something like "r.a := b;", how does the compiler perform the range check (either at compile time or at runtime)?
Given the original definition of "a" as "integer", the compiler could generate code to ensure that the value of "b" was within the range of integer (assuming that "b" is of a type with a larger range).
There are really two checks of importance here. One is the simple range check upon an assignment to "a". That would be no different in implementation from any other range check, e.g., for assignment to a simple variable. The other is the variant check when a field of a variable of type "r" is accessed. This latter check simply requires that "a" be verified as having the correct value for access to the designated variant part. Given that a specific variant part may be activated by a range of values, a range check is appropriate in this case as well.
I confess that I do not know the EP standard well enough to say with certainty whether it is illegal to assign to "a" a value that is within the range of "a"'s type but not one of the case-constant-list values. In other words, is:
rcd.a := 2;
...an error? Or does an error occur only if a field reference is made subsequently (because at that point the selector is not valid for the given field reference)? I can't find language in the standard that prohibits the above assignment, so I suspect but am not certain that it is legal.
-- Dave