From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!rochester!bbn!inmet!ishmael!inmet!stt From: stt@inmet Newsgroups: comp.lang.ada Subject: Re: nested variant records query Message-ID: <124000047@inmet> Date: 1 Jun 89 08:45:00 GMT References: <40671@bbn.COM> Nf-ID: #R:bbn.COM:-4067100:inmet:124000047:000:1844 Nf-From: inmet!stt Jun 1 04:45:00 1989 List-Id: 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