comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: 64bit access to an array of 8bit values
Date: Mon, 04 Mar 2002 07:23:26 GMT
Date: 2002-03-04T07:23:26+00:00	[thread overview]
Message-ID: <3C8320E2.165443BE@acm.org> (raw)
In-Reply-To: 3C823A1A.6030006@users.sf.net

If you're willing to limit yourself to those machines that actually have
8-bit byte access (which your code would require), you can do

type Bit8 is new Interfaces.Unsigned_8;
-- This won't compile on machines that don't have 8-bit byte access.

type Bit64 is mod 2 ** 64;

type Ram_List is array (Natural range <>) of aliased Bit8;
for Ram_List'Component_Size use Bit8'Size;
pragma Pack (Ram_List);

Bytes_Per_Quad_Word : constant := 8;

subtype Quad_Word_As_Ram_List is Ram_List (1 .. Bytes_Per_Quad_Word);

function To_Quad_Word is new Ada.Unchecked_Conversion
(Source => Quad_Word_As_Ram_List, Target => Bit64);
function To_Ram_List is new Ada.Unchecked_Conversion
(Source => Bit64, Target => Quad_Word_As_Ram_List);

Ram   : Ram_List (0 .. Whatever);
Value : Bit64;
...
Value := To_Quad_Word (Ram (Ram'First .. Ram'First + Bytes_Per_Quad_Word
- 1) );

If you really need to have access values then you should look into
System.Address_To_Access_Conversions, and convert the address of the
first byte of the 64-bit value to the access-to-64-bit-value type.

To be really portable, you need to decide what byte order you want your
64-bit values to have, and do the appropriate conversion on machines
with a different endianness.

-- 
Jeff Carter
"Nobody expects the Spanish Inquisition!"
Monty Python's Flying Circus



      parent reply	other threads:[~2002-03-04  7:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-03 14:58 64bit access to an array of 8bit values Dave Poirier
2002-03-03 15:38 ` Jim Rogers
2002-03-03 18:02 ` John R. Strohm
2002-03-03 16:39   ` Dave Poirier
2002-03-03 17:27   ` Jeffrey Creem
2002-03-05 20:49     ` John R. Strohm
2002-03-05 23:52       ` Jeffrey Creem
2002-03-06  7:30         ` John R. Strohm
2002-03-06 11:50           ` Jeffrey Creem
2002-03-07 20:03             ` John R. Strohm
2002-03-04 10:29   ` Robert Dewar
2002-03-04 13:02     ` Larry Kilgallen
2002-03-04 13:41       ` Dave Poirier
2002-03-03 22:24 ` David C. Hoos, Sr.
2002-03-03 22:51   ` Dave Poirier
2002-03-04  2:40     ` David C. Hoos, Sr.
2002-03-04  4:08     ` David Starner
2002-03-04 10:31   ` Robert Dewar
2002-03-04 18:00   ` Warren W. Gay VE3WWG
2002-03-04  3:15 ` Pat Rogers
2002-03-04  7:23 ` Jeffrey Carter [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox