From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: Mon, 23 Aug 93 09:17:54 CDT From: crispen@eight-ball.boeing.com (Bob Crispen) Subject: Re: Data Overlays Message-ID: <9308231417.AA20947@eight-ball.boeing.com> List-Id: >From: cis.ohio-state.edu!magnus.acs.ohio-state.edu!csn!news.den.mmc.com!iplmai l!jcrigler@ucbvax.Berkeley.EDU (Jim Crigler) asks: [and when are we going to get the AJPO host not to put the verbose Bitnet string on here?] >What about a variant record? Language Lawyer question (my LRM is at >home): are rep. specs allowed on variant records? If so (and if you >have a single tag at any level that determines what the message is at >that level), use an address clause to store the data on the Byte_Array, >then use the variant to figure out what you've got. Alas, this works only when the initial field is the discriminant for the record (though one could have a fill-in-the-blanks discriminant field, but my dim recollection is that coping with this is way uglier than Unchecked_Conversion). Yes, you absolutely can have rep specs on record types with discriminants. The only exception is that if you have an unconstrained array in the record, you probably can't do what you want. For example: package Bar is type An_Index is range 0..5; type An_Array is array (An_Index range <>) of Integer; type A_Big_Array is array (An_Index) of Integer; type A_Small_Array is array (An_Index range 0..1) of Integer; type Long_Boolean is (False, True); for Long_Boolean'size use 32; type Bad_Record (Size : An_Index) is record The_Array : An_Array (0..Size); end record; type Good_Record (Big : Long_Boolean) is record case Big is when True => The_Array : A_Big_Array; when False => The_Overlay : A_Small_Array; end case; end record; for Bad_Record use record Size at 0 range 0..31; The_Array at 4 range 0..(6 * 32)-1; ------^A ## # --### A:error: RM 13.4(7): component subtype must be static end record; for Bad_Record'size use (7 * 32) - 1; -------^A ## # --### A:error: RM 13.2(6): type and its subcomponents must have static constrai nts for Good_Record use record Big at 0 range 0..31; The_Array at 4 range 0..(6 * 32)-1; The_Overlay at 4 range 0..(2 * 32)-1; end record; for Good_Record'size use (7 * 32) - 1; end Bar; With respect to messages, the least ugly way I've found is, just as Bill Gilbert says, to use Unchecked_Conversion to do overlays into byte arrays. +-------------------------------+--------------------------------------+ | Bob Crispen | Who will babysit the babysitters? | | crispen@foxy.boeing.com +--------------------------------------+ | (205) 461-3296 |Opinions expressed here are mine alone| +-------------------------------+--------------------------------------+