comp.lang.ada
 help / color / mirror / Atom feed
From: John Harbaugh <john.s.harbaugh2@boeing.com>
Subject: Re: Variant Record Component
Date: Fri, 28 Feb 2003 22:07:20 GMT
Date: 2003-02-28T22:07:20+00:00	[thread overview]
Message-ID: <3E5FDD98.388AC976@boeing.com> (raw)
In-Reply-To: hKN7a.268774$SD6.13767@sccrnsc03

Freezing rules are defined in ARM 13.14.  In short, freezing is the
point either in compilation or elaboration at which the memory structure
of an entity must be fixed.  Because of these rules, the following
representation clause is illegal:

   type Byte is mod 2**8;
   
   subtype Nibble is Byte range 0..2*4;
   for Nibble'Size use 4;

In the case of the variant record in question, the record type does not
have a defaulted discriminant (a definite type).  When a record object
is declared, a discriminant value must be supplied (a constrained
object), at which point the structure of the object is "frozen" at
compile time.  If, on the other hand, the record type had a default
expression for the discriminant (an indefinite type) and the object
declaration did not override the default (an unconstrained object), then
freezing would also occur at runtime, because the structure could change
(through whole-value assignment).  Variant records a are a little subtle
in this regard.

You are correct, the field "b" may not exist, in which case a
Constraint_Error is raised when the nonexistent field is referenced.

So, I guess it really is unnecessary to have a language feature to test
the structure.  One can simply test the discriminant.  In this
particular case, I would still advocate for re-factoring the routine
because it is obscenely big, but that's another issue.

Cheers,

	- John

> Constraint_Error because of errors in the data (a field is out of range,
> for instance), or because the program referenced msg.b when the
> discriminant/case statement said there was no field "b"?  In the latter
> case, it sounds like the symptom is the attempt to reference msg.b, but the
> problem is erroneously thinking this message is of the subtype with a "b".



  reply	other threads:[~2003-02-28 22:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-26 18:00 Variant Record Component John Harbaugh
2003-02-26 19:08 ` Stephen Leake
2003-02-27  8:17   ` Anders Wirzenius
2003-02-27  8:46     ` John McCabe
2003-02-27 17:26     ` phone number database Stephen Leake
2003-02-27 18:09       ` tmoran
2003-02-28  0:07       ` Matthew Heaney
2003-02-28  6:46       ` Hijacking threads (was phone number database (was Variant Record Component)) Anders Wirzenius
2003-02-26 20:50 ` Variant Record Component David C. Hoos
2003-02-28 16:15   ` John Harbaugh
2003-02-28 18:18     ` tmoran
2003-02-28 22:07       ` John Harbaugh [this message]
2003-02-28 20:51     ` Randy Brukardt
2003-03-01  2:34     ` Jeffrey Carter
2003-03-03  9:24     ` John McCabe
2003-02-26 21:37 ` tmoran
  -- strict thread matches above, loose matches on Subject: below --
2003-02-28 19:40 David C. Hoos
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox