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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5ae752c88e0dde5e X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news4.google.com!feeder.news-service.com!news.netcologne.de!ramfeed1.netcologne.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Using representation clauses in networking software Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <8739ugqfeb.fsf@mid.deneb.enyo.de> Date: Sun, 15 Aug 2010 16:32:47 +0200 Message-ID: <43fkp7an4c5m$.3db3n6adym42.dlg@40tude.net> NNTP-Posting-Date: 15 Aug 2010 16:32:45 CEST NNTP-Posting-Host: d3299c26.newsspool3.arcor-online.net X-Trace: DXC=?D7\65mFPGFFJ3]dH>I?oEMcF=Q^Z^V3H4Fo<]lROoRA8kF9M9ZW;W]O;6EL X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:13337 Date: 2010-08-15T16:32:45+02:00 List-Id: On Sun, 15 Aug 2010 15:44:34 +0200, Yannick Duch�ne (Hibou57) wrote: (I agree with what you wrote. I am programming a lot of communication stuff, but never used representation clauses to handle endianness.) > I do not know neither any representation clause for Byte Ordering. Byte ordering is what S'Bit_Ordering is, when bytes are addressable. IMO, Bit_Ordering was an unfortunate choice. The attribute name suggests ordering of bits in some machine storage unit, which it is not. > Just to try to meet your request (something else later) : I do not know a > way to have a method which would automatically know the bit order of its > platform, Bit order is useless if bits are not directly addressable. > except perhaps receiving a standard data, like 16#1234# > (0x1234), and then check if it looks like 16#3412# or like 16#1234#. This would determine byte ordering. Bit ordering is when you serialize a sequence of bits {0, 0, 0, 0, 0, 0, 0, 1} and get 2#1000_0000# (little endian) 2#0000_0001# (big endian). Most types of hardware have opaque bytes compatible with the machine, e.g. UARTs. If the hardware is not, then representation clause would not be my choice anyway. I would recode bytes or whatever units immediately as obtained from the device: type Strange_Octet is mod 2**8; Decode_Strange_Octet : array (Strange_Octet) of Unsigned_8 := ( 2#0000_0001# => 2#0000_1000#, 2#0000_0010# => 2#0000_0100#, 2#0000_0011# => 2#0000_1100#, ... ); > Or else you may suggest it for a future Ada revision (via this newsgroup > or else ada-auth.org ). One could introduce enumeration representation clauses for modular types, e.g. type Strange_Octet is mod 2**8; for Strange_Octet use (2#0000_0001# => 2#0000_1000#, ...); Better would be to allow user-defined integer literals, so that the programmer could define its own type. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de