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=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.unit0.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Creating several types from a base type and conversion Date: Sun, 19 Jan 2020 17:24:27 +0200 Organization: Tidorum Ltd Message-ID: References: <4b0649b3-aed2-44fd-822f-d6665b9352dd@googlegroups.com> <536e9961-f454-44d9-95a6-aecaaee1addf@googlegroups.com> <516be7e3-4be3-4697-adb0-9fbde4d5b7e6@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net ChgoypnVqMUTCjajBw1S7A3KzMdIcbtTXzsA+h6PtFN4JWVS7I Cancel-Lock: sha1:/GfW58k3DacUHSyQtCll0xPkLlw= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 In-Reply-To: Content-Language: en-US Xref: reader01.eternal-september.org comp.lang.ada:57898 Date: 2020-01-19T17:24:27+02:00 List-Id: On 2020-01-19 16:51, Simon Wright wrote: > AdaMagica writes: > >> Am Sonntag, 19. Januar 2020 10:37:21 UTC+1 schrieb Simon Wright: >>> representation clauses where endianness is involved are a lot more >>> confusing than shifts and masks. In my experience, record-representation clauses with non-default Bit_Order work well as long as you don't exceed the size of the largest machine scalar (so 32 bits are ok for most systems, 64 bits for some) and as long as you don't use record components whose types are themselves records with representation clauses (if Bit_Order is not the default, GNAT insists on widening the component types to the nearest larger-or-equal machine scalar, so a 5-bit record, say, is widened to an 8-bit record and GNAT then insists on using at least 8 bits for any component of that type, which usually breaks the lay-out of the higher-level record). >> See https://en.wikibooks.org/wiki/Ada_Programming/Attributes/%27Bit_Order >> >> This is a complete description of how far we can get with endian >> independence in current Ada. Ada 202x won't change anything in this >> respect. > > The description is still, I feel, confusing. > > That said, I found this incantation (for an SNTP packet, which is > transmitted in network byte order) works a treat on this LE machine. I > don't have a BE machine to check it on (but the original code was used > on both BE and LE machines). > > end record > with > Bit_Order => System.High_Order_First, > Scalar_Storage_Order => System.High_Order_First, Note that Scalar_Storage_Order is GNAT-specific and not Ada standard. > Size => 48 * 8; > -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .