"J. David Bryan" wrote:
On 19 Nov 2002 at 10:11, Eike Lange wrote:
I'm not sure wether it's a feature or a bug but I've read, that setting a case selector in variant records makes some variants unavailable from this point.
ISO-7185 (Pascal) and ISO-10206 (Extended Pascal) say:
6.5.3.3 Field-designators
[...]
It shall be an error unless a variant of a record-variable is active for the entirety of each reference and access to each component of the variant.
So you are correct (a variant part becomes "active" when the selector value matches the associated case constant).
The following program demonstrates, that setting a case selector allows further overwriting of unselected variants:
The standards also say:
3.2 Error
A violation by a program of the requirements of this International Standard that a processor is permitted to leave undetected.
So GPC complies with the ISO standards.
- how _should_ GPC behave?
GPC behaves correctly now, but it would perhaps be more useful if variant assignments were checked at run time as part of the general implementation of range checking (which is on the "to do" list).
This particular error is **very** hard to detect at run-time in any efficient manner. It means treating variant records entirely differently from any other type of record. Note that nothing requires handling the components within a with statement.
While I am one of the biggest mutterers about the lack of run-time range-checking, I would not expect this one to ever be implemented. It is even impossible if the variant selector is not stored, as in:
athing = RECORD a, b : integer; CASE c OF c1: ( d : boolean) c2: ( e : real) END; END; (* record athing *) ... thing : athing; thingptr : ^athing;
When "thing.e := realvalue" is always legal unless the variable declaration was of the form:
new(thingptr, c1); ... WITH thingptr^ DO BEGIN c2 :=- realvalue; (* possibly detectable *) END;
because how can you then handle:
dispose(thingptr); new(thingptr, c2); etc.
and I am not willing to give up the freedom of variant records with no selector element.