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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM 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-7-bit Path: g2news1.google.com!postnews.google.com!l6g2000yqb.googlegroups.com!not-for-mail From: Shark8 Newsgroups: comp.lang.ada Subject: Re: Using representation clauses in networking software Date: Sun, 15 Aug 2010 12:11:18 -0700 (PDT) Organization: http://groups.google.com Message-ID: <22411485-ae7e-43d3-8be4-c488f1178d30@l6g2000yqb.googlegroups.com> References: <8739ugqfeb.fsf@mid.deneb.enyo.de> <43fkp7an4c5m$.3db3n6adym42.dlg@40tude.net> <8739ugkka6.fsf@mid.deneb.enyo.de> <1pjh30gv98n9t$.lycfvhr1l9rz$.dlg@40tude.net> <87tymvhoy5.fsf@mid.deneb.enyo.de> <1x3jdyxqnl1e7.xlqx0giurt0x.dlg@40tude.net> <1uzfyshtk9wpq.1ft0ehpgbw60k.dlg@40tude.net> NNTP-Posting-Host: 174.28.232.29 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1281899479 14882 127.0.0.1 (15 Aug 2010 19:11:19 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 15 Aug 2010 19:11:19 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l6g2000yqb.googlegroups.com; posting-host=174.28.232.29; posting-account=lJ3JNwoAAAAQfH3VV9vttJLkThaxtTfC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 ( .NET CLR 3.5.30729; .NET CLR 4.0.20506),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:13355 Date: 2010-08-15T12:11:18-07:00 List-Id: Here's what I've been using to swap endian-ness... as you can see though it is the "programmer's responsibility" to use it and use it correctly; a representation clause for endian-ness might not be a bad thing, it would make implementing the protocols which do specify the endian-ness easier though. -- 8-bit 'word' [Byte] Type Word8 is mod 2**8; For Word8'Size use 8; -- Array of some number of bits... I am assuming that a single unit- size will not exceed 255-bits. Type Bit_Array is Array (Word8 range<>) of Boolean; Pragma Pack(Bit_Array); ---- Function for swapping big-endian to little-endian and vice versa. Procedure Swap( B : in out Bit_Array ) is Low, High : Bit_Array(1..B'Length/2); For Low'Address use B'Address; For High'Address use B(1+B'Length/2)'Address; begin Case B'Length is when 64 | 32 | 16 => Swap( Low ); Swap( High ); B(1..B'Length):= High & Low; when 8 | 4 | 2 | 1 | 0 => null; when others => raise Program_Error; -- Non powers of 2 are not supported; and sizes in excess of 64-bits. end case; end Swap;