From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Using representation clauses in networking software
Date: Sun, 15 Aug 2010 12:11:18 -0700 (PDT)
Date: 2010-08-15T12:11:18-07:00 [thread overview]
Message-ID: <22411485-ae7e-43d3-8be4-c488f1178d30@l6g2000yqb.googlegroups.com> (raw)
In-Reply-To: 1uzfyshtk9wpq.1ft0ehpgbw60k.dlg@40tude.net
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;
next prev parent reply other threads:[~2010-08-15 19:11 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-15 11:33 Using representation clauses in networking software Florian Weimer
2010-08-15 13:44 ` Yannick Duchêne (Hibou57)
2010-08-15 14:32 ` Dmitry A. Kazakov
2010-08-15 14:44 ` Florian Weimer
2010-08-15 15:04 ` Dmitry A. Kazakov
2010-08-15 15:32 ` Florian Weimer
2010-08-15 16:10 ` Dmitry A. Kazakov
2010-08-15 16:40 ` Yannick Duchêne (Hibou57)
2010-08-15 17:58 ` Dmitry A. Kazakov
2010-08-15 19:11 ` Shark8 [this message]
2010-08-15 19:15 ` Simon Wright
2010-08-15 20:25 ` Maciej Sobczak
2010-08-15 21:24 ` Simon Wright
2010-08-16 6:40 ` Dmitry A. Kazakov
2010-09-04 20:46 ` Florian Weimer
2010-08-15 15:39 ` Yannick Duchêne (Hibou57)
2010-08-15 15:31 ` Yannick Duchêne (Hibou57)
2010-08-15 15:30 ` Yannick Duchêne (Hibou57)
2010-08-15 16:10 ` Dmitry A. Kazakov
2010-08-16 10:57 ` Stephen Leake
2010-08-15 15:58 ` Simon Wright
2010-08-15 16:03 ` Florian Weimer
2010-08-17 3:32 ` Randy Brukardt
2010-08-16 9:12 ` anon
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox