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: Fri, 11 May 2018 09:02:06 +0100 Organization: A noiseless patient Spider Message-ID: References: <9af47760-e731-4cb5-a1a0-d63e31019ce5@googlegroups.com> <877eob1cc6.fsf@nightsong.com> <87po23yusb.fsf@nightsong.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="906cab77493fe040d97f450db9e7653d"; logging-data="19700"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19VUzhTCDPwIVDz21eRjSok4zLrFv9KOwc=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (darwin) Cancel-Lock: sha1:EUGVeUeBIpqk9Lom/oCpcPR9SFg= sha1:vbFrDrMPxCk5KxsMXYnpnL1B8UE= Xref: reader02.eternal-september.org comp.lang.ada:52250 Date: 2018-05-11T09:02:06+01:00 List-Id: Paul Rubin writes: > "Dan'l Miller" writes: >> Btw, bitfields in C and in Erlang are •the• roughly analogous language >> feature corresponding to representation clauses in Ada [...] > That is, if you use a hypothetical endianness representation clause to > declare something like "type bigint32 is int32 big_endian", then a > record containing "x, y : bigint32" will actually require x and y to > be stored in memory in big-endian byte order, and will show up that > way if you dump the memory region to disk. > > That particularly means if the hardware happens to be little-endian > and you want to add x and y together with a 32-bit "add" machine > instruction, you are requiring the compiler to generate code that > reads x and y from memory and performs byte swaps before doing the > addition. One would hope that the design review would catch this mistake. > I've never seen a network program do it like that though. Everyone > just makes sure that network integers are converted to the host format > before being stored in memory, and converted back when sent over the > network. Which is exactly what a competent Ada team would do, too. No different from ensuring that the units are sensible: just because the network data is in feet and pounds is no reason for the system to work internally in other than metric units.