comp.lang.ada
 help / color / mirror / Atom feed
From: stt@inmet
Subject: Re: nested variant records query
Date: 1 Jun 89 08:45:00 GMT	[thread overview]
Message-ID: <124000047@inmet> (raw)
In-Reply-To: 40671@bbn.COM


A nested variant record need not be constrained
if defaults are provided for the discriminants
when the nested record type is defined.
However, this will generally leave room for the
maximum possible instance.
Otherwise, the discriminant of a nested record
must be predefined, or the same as one of the
discriminants of the enclosing record type.

For example:
    type rec(d : boolean := false) is record ... end record;
    type bigrec(a : integer; b : boolean) is record
       case a is
          when 1 =>
             r : rec(b);  -- discrim same as one of encloser
          when 2 =>
             s : rec;     -- discrims have defaults,
                          -- this will normally be "max-size"
	  when 3 =>
             t : rec(g(5)>h(3);  -- discrim calculated once,
                         -- used for all instances of bigrec
          when others =>
             null;
       end case;
    end record;

Alternative approaches generally involve using arrays of bytes,
or even bits, and doing your own layout, perhaps including
unchecked conversions to/from access types if you know
what you are doing.

Generally, relying on variant records, nested or otherwise,
to have a specific bit layout is "iffy" at best, since
there are frequently "hidden" fields added into the
record, depending on the particular compiler.
These hidden fields may be "dope" for nested arrays,
self-relative offsets to nested dynamic-length components,
discriminants of nested records (these aren't really "hidden"
but are sometimes unexpected), etc.  Record rep clauses
can sometimes overcome these difficulties, but this whole
area of hidden fields is compiler-dependent.

Hence, controlling your own destiny via an array of bytes/bits
is probably the safest and most portable across compilers.

S. Tucker Taft
Intermetrics, Inc.
Cambridge, MA  02138

      reply	other threads:[~1989-06-01  8:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-05-31  2:15 nested variant records query John Morrison
1989-06-01  8:45 ` stt [this message]
replies disabled

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