comp.lang.ada
 help / color / mirror / Atom feed
From: lutz@iks-jena.de (Lutz Donnerhacke)
Subject: Re: Query on portable bit extraction
Date: Fri, 26 Oct 2001 17:08:31 +0000 (UTC)
Date: 2001-10-26T17:08:31+00:00	[thread overview]
Message-ID: <slrn9tj649.8os.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: 3BD99406.62B13405@Raytheon.com

* Mark Johnson wrote:
>We have code that we want to run on both a big (sgi) and little (pc)
>endian machine. As an example, the layout of the data in memory is...
>[big_endian bit order]
>Byte  0 1 2 3 4 5 6 7
>21 -  X X X Y Y Y Y Y
>22 -  Y Y Z Z Z Z Z Z
>where we need to extract XXX as the "wait code", YYYYYYY as the "value",
>and ZZZZZZ is a pad area (don't care).

>Thinking of records & representation specifications, I'd like to be able
>to do something like this...
>  subtype Wv is Natural range 0..7;
>  subtype Vv is Natural range 0..127;
>  subtype Pv is Natural range 0..63;
>  type Wait_Value is
>    record
>      Wait : Wv;
>      Value : Vv;
>      Pad : Pv;
>    end record;
>  for Wait_Value use
>    record
>      Wait at 0 range 0..2;
>      Value at 0 range 3..9;
>      Pad at 1 range 2..7;
>    end record;
>  for Wait_Value'Bit_Order use System.High_Order_First;

Incorrect code: Value does cross a Storage_Element boundary. Split it into
two parts and combine them later. Example:
http://www.iks-jena.de/mitarb/lutz/ada/net/ --> i.e. IPV4 Header
 
>which looks pretty reasonable until I get the following GNAT error
>messages on the PC...
> error: attempt to specify non-contiguous field not permitted
> error: (caused by non-standard Bit_Order specified)

Correct. for xx'Bit_Order use ... does only define the direction of counting.
It does not swap or correct alignments.

>somewhere, I recode the representation specification to be...
>  for Wait_Value use
>    record
>      Wait at 1 range 5..7;
>      Value at 0 range 6..12;
>      Pad at 0 range 0..5;
>    end record;
>(assuming System.Low_Order_First bit order) which works as expected.

On both systems? Very strange.




  reply	other threads:[~2001-10-26 17:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-26 16:49 Query on portable bit extraction Mark Johnson
2001-10-26 17:08 ` Lutz Donnerhacke [this message]
2001-10-27  0:06 ` Jeffrey Carter
2001-10-27  4:23   ` Steven Deller
2001-10-27 16:31     ` Nick Roberts
2001-10-28  1:30       ` Jeffrey Carter
2001-10-28 19:07         ` Bit_Order useful [was Query on portable bit extraction] Nick Roberts
2001-10-29  1:23           ` Robert Dewar
2001-10-29  1:25       ` Query on portable bit extraction Robert Dewar
replies disabled

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