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: Thu, 10 May 2018 20:28:49 +0100 Organization: A noiseless patient Spider Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="4ad62473ff9dd9ec67a499bd743818bb"; logging-data="12298"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Wg5KCczN2WfLarlGN7wbxMcl3vW5Yl9o=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:84II4XTNp5l4qqjszPeC9OD1Bno= sha1:majZOaHNwyADwPwPS5/MSrg2SXc= Xref: reader02.eternal-september.org comp.lang.ada:52204 Date: 2018-05-10T20:28:49+01:00 List-Id: "Dan'l Miller" writes: > so the ••representation clause•• in AI12-0218 (on only GNAT for now) > is the only game in Adatown I don't have a reference, but there was a cunning plan once involving the fact that Boolean'Pos (False) is 0, and Boolean'Pos (True) is 1. So you could write expressions involving BE : constant := Boolean'Pos (System.Default_Bit_Order = System.High_Order_First); & likewise for LE, and you could then write representation components as (le-value * LE + be-value * BE) (something like that, anyway). Ugh. But you still have to byte-swap. The worst case I came across was where the remote system was LE, the network was LE (there's British for you), we were BE, and the interface device - in a spirit of helpfulness - did byte-swapping for you assuming that the whole message consisted of 16-bit values (because the message header did, and that was the only bit they needed to deal with; they were on a BE device). Bad luck if one of the message fields was 32-bits. It is a pain in the neck, and something that newer programmers found hard to get their heads round, but it is only needed at the edges of the system (letting byte-swapping inside the system proper is going to be very expensive).