Variant records (EP)
Waldek Hebisch
hebisch at math.uni.wroc.pl
Wed Mar 2 04:55:35 CET 2005
Frank Heckenbach wrote:
> A question to the EP experts? Is the following program valid EP, and
> if so, what should its output be?
>
> program Foo (Output);
>
> type
> i23 = 2 .. 3 value 2;
> a = record
> b: Integer value 1;
> case c: i23 of
> 2: (d: Integer value 4);
> 3: (e: Integer value 5)
> end value [b: 6; case c: 3 of [e: 7]];
>
> var
> v: ^a;
>
> begin
> New (v, 2);
> WriteLn (v^.b, ' ', v^.c, ' ', v^.d)
> end.
>
...
> : 6.7.5.3 Dynamic allocation procedures
> :
> : It shall be an error if a variant of a variantpart within the new variable
> : is active and a different variant of the variantpart is one of the
> : specified variants.
> :
IMHO the above means that the program is incorrect. Since the type
specifies the initial state, variant corresponding to 3 is
active nad you are not allowed to specify different variant to `new'.
> Or is this `New' statement invalid? If anything, paragraph 3 might
> be a reason, but AFAICS it's meant to forbid invalid combinations of
> selectors in nested variant records, and doesn't apply here.
From 6.4.3.4
: The value of the selector of the variant type shall cause the associated
: variant of the variant-part to be designated active.
So once we apply the inital state corresponding variant is designated
active and by the paragraph 3 if we specify different variant, we have
an error.
>
> The more general question is whether the initial states of the
> components of a structured type can have any influence when the
> structured type itself has a `value' specification. (Since I don't
> see another way how they could.)
>
AFAICS no -- it seem that `value' specification is required to be
complete.
--
Waldek Hebisch
hebisch at math.uni.wroc.pl
More information about the Gpc
mailing list