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=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,43ad9ab56ebde91c X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.204.152.89 with SMTP id f25mr959658bkw.0.1323709645438; Mon, 12 Dec 2011 09:07:25 -0800 (PST) MIME-Version: 1.0 Path: jh9ni3856bkb.0!nntp.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.nethere.com!news.nethere.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 12 Dec 2011 11:07:24 -0600 Newsgroups: comp.lang.ada Subject: Re: Does Ada support endiannes? From: csampson@inetworld.net (Charles H. Sampson) Date: Mon, 12 Dec 2011 09:07:24 -0800 Message-ID: <1kc5n51.ffg0umddufyfN%csampson@inetworld.net> References: <23835087-313f-427c-b37e-4ff1bdef9d57@r6g2000yqr.googlegroups.com> <20e631fc-e7b4-41ca-be0f-aab8be3f9a25@f33g2000yqh.googlegroups.com> <53n2sd7edt5i.1boh4452h0aks.dlg@40tude.net> User-Agent: MacSOUP/2.8.2 (Mac OS X version 10.4.11 (PPC)) X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-Y3yxIa5GPLzLVCB0O3myjawNOLhODlWprHB5UC0nzzFwyDJgR/8u4TdLAj3kib49W3cbEz7newfaBrF!o6QTLrWrspDWhyxr1JQNGVMtbyjfWbmVLnHtUa3YsHsLlDP2ellgXedgEFHtSeVvtKOpy9APD3Ol!wwTKzdtNepvEt5tPL6r/9stJTpw= X-Complaints-To: abuse@nethere.com X-DMCA-Complaints-To: abuse@nethere.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3668 Date: 2011-12-12T09:07:24-08:00 List-Id: Dmitry A. Kazakov wrote: > On Mon, 12 Dec 2011 04:46:22 -0800 (PST), Gerd wrote: > > > On 12 Dez., 12:27, "Dmitry A. Kazakov" > > wrote: > > > > Any suggestion on how to convert, others than using "/" and "mod"? > > Why not to use them? It would be a bad idea trying to avoid them. > > It won't give you much performance, because memory mapping would require > unpacking, alignment, checksum evaluation, stuff which would turn into > extra copying. So why not just: > > type Octet is new Unsigned_8; > type Word is new Unsigned_16; > type Octet_Array is array (Positive range <>) of Octet; > > procedure Get_Little_Endian (Data : Octet_Array; Index : in out Integer; > Value : out Word) is -- No extra copying > begin > Value := Word (Data (Index)) + Word (Data (Index + 1)) * 256; > Index := Index + 2; > end Get_Little_Endian; > > ... Don't you think this approach obscures what's going on, Dmitry, thereby negating one of the design goals of Ada? Sure, most of us who have bit-twiddled in the bad old days can figure out what's going on, or at least convince ourselves that we've figured out what's going on, but I much prefer the clarity of something like type Single_Precision is -- old IBM single-precision record Negative : Boolean; Characteristic : Seven_Bit_Integer; Mantissa : Twenty_Four_Bit_Fixed_Point; end record; A_Variable : Single_Precision; ... A_Variable := ( Negative => ... Characteristic => ... Mantissa => ...); LIke you, I've worked on a hard real-time system that had to interface with hardware having a lot of different protocols and interfaces. My experience was that worries about code efficiency were more apparent than real. Charlie P. S. Please forgive any errors in the syntax of my example. I don't have a compiler available to check them with. P. P. S. I don't advocate the style of the above assignment statement. I used the first newline only to retain control of the column alignment. In a reasonable development system, I'd let the editor handle that for me. -- [A certain TV newsreader] had a role to play: presenter of the Other Side of the Argument, to whom fair-minded people were obligated to pay heed, no matter what nonsense he spouted. Charlie Pierce, Idiot America