From: | Marco van de Voort <marcov@turtle.stack.nl> |
Newsgroups: | comp.compilers |
Date: | Thu, 30 Dec 2010 17:14:41 +0000 (UTC) |
Organization: | Stack Usenet News Service |
References: | 10-12-040 10-12-052 10-12-059 |
Keywords: | design, storage |
Posted-Date: | 30 Dec 2010 23:01:30 EST |
On 2010-12-29, Hans-Peter Diettrich <DrDiettrich1@aol.com> wrote:
>> I suppose I have an initial prejudice against variant records. They seem to me
>> to be a potential source of hard to find bugs (for the user programmer, I mean,
>> not the compiler designer). Am I wrong about this? Is it possible for the
>> compiler to always know which type is active in the variant, like say through
>> a hidden compiler-generated variable in the record?
>
> Most (Wirthian) variant records have an (optional) Tag field, but most
> implementations don't use it for the selection of one variant at
> runtime, most probably for compiler simplicity and performance issues.
> Ada may be more strict here (dunno).
>
> At least there must exist rules for what happens when the Tag field is
> changed. IMO the variant part should be cleared then - otherwise the Tag
> if of no real value for the compiler and coder.
In Delphi it doesn't make sense, but what I remember from reading ISO
Pascal sites (Scott Moore's, GPC) it made sense there, because in ISO Pascal
it is possible to dynamically allocate memory for different cases of the
variant record. And the allocated sizes of the cases could differ.
The tag field(s) were used to select the correct variant (and thus size)
using special new syntax like new(x,tag1[,tagn]);
Return to the
comp.compilers page.
Search the
comp.compilers archives again.