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!reader02.eternal-september.org!.POSTED!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: AI12-0218: What is the portable representation clause for processing IETF packets on little-endian machines? Date: Sat, 12 May 2018 08:08:40 +0100 Organization: A noiseless patient Spider Message-ID: References: <9af47760-e731-4cb5-a1a0-d63e31019ce5@googlegroups.com> <877eob1cc6.fsf@nightsong.com> <5c9b9f90-884f-4de7-8663-d39a67949f4f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="386cd22a5277e61cff5810e5bbe13a1a"; logging-data="17251"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18b4+HbUcLzaUqDi6E6vAeNZGPdHsDeY3o=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:IHh87mAxXgwrzJeGF3nMor5XmnI= sha1:ZFTbyoMrb0eIjTDIVP8bbbEtoQE= Xref: reader02.eternal-september.org comp.lang.ada:52308 Date: 2018-05-12T08:08:40+01:00 List-Id: "Jeffrey R. Carter" writes: > On 05/11/2018 11:39 PM, Simon Wright wrote: >> >> whereas Ada2012 says >> >> "To convert a record from one representation to another, two >> record types with a common ancestor type need to be declared, >> with no inherited subprograms." >> >> which seems to require _three_ types. > > The example in 13.6 shows this with only 2 types. This is because a > type is defined to be its own ancestor (ARM 3.4.1). I saw the example. I stand by my statement that it's confusing. Perhaps there needs to be a way to mark a language usage as domain-specific rather than natural; in English, I am not my own ancestor (or descendant). >> But in any case your code doesn't answer my question: what >> representation trick could convert between >> >> type T is record >> J : Integer; >> end T; >> >> and >> >> type BE_T is new T; >> for BE_T use record >> ????? >> end record; > > I was showing how to use records with representations to get the > compiler to do byte swapping for you. There's no way to use them to > change the byte order of an integer type directly. Not quite the same, but I think I showed upthread a conversion that does this: function To_Fixed_32_16 (S : Four_Byte_Slice) return Fixed_32_16 is function Convert is new Ada.Unchecked_Conversion (Four_Byte_Slice, Fixed_32_16); begin if Big_Endian then return Convert (S); else return Convert ((1 => S (4), 2 => S (3), 3 => S (2), 4 => S (1))); end if; end To_Fixed_32_16; Of course, in C you'd use ntohl(), but we'd have to wrap something like the above in a generic.