comp.lang.ada
 help / color / mirror / Atom feed
From: karlran1234@yahoo.com (Karl Ran)
Subject: Ada records and byte order
Date: 23 Jun 2001 03:15:23 -0700
Date: 2001-06-23T10:15:23+00:00	[thread overview]
Message-ID: <e7ebd224.0106230215.3f684ac6@posting.google.com> (raw)

Hi there,

I've a question about Ada records:

I have to read a binary file from disk which was written by another program.

The record size is fixed: 3 bytes
The file structure looks like this:
      

|byte 1 | |byte 2 | |byte 3 |   |byte 4...
aaaa.aaaa.bbbb.bbbb.bbbb.cccc | aaaa.a.....
M       L M            L M  L
S       S S            S S  S
B       B B            B B  B

a:  8 bits
b: 12 bits
c:  4 bits

Here is the code ...

procedure test is

   subtype BYTE     is Integer range 0 .. 2 **   8 - 1;
   subtype WORD12   is integer range 0 .. 2 **  12 - 1;
   subtype WORD4    is integer range 0 .. 2 **   4 - 1;

   type My_rec is
      record
         A : BYTE;
         B : WORD12;
         C : WORD4;
      end record;
   
   for My_rec use
      record
         A at 0 range 0 ..  7;
         B at 1 range 0 .. 11;
         C at 2 range 0 ..  3;
      end record;   

   Abc : My_Rec; 

begin
   Abc.b := 16#123#;
   ...
end test;
   
... which fails to compile whith GNAT on a (low-endian) i386:
test.adb:31:10: component "C" overlaps "B" at line 30
         
Is there an Ada like (TM) solution for this kind of (byte order) problem?

   
Thanks,
Karl



             reply	other threads:[~2001-06-23 10:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-23 10:15 Karl Ran [this message]
2001-06-23 11:18 ` Ada records and byte order Carbonne Damien
2001-06-23 16:35 ` Jeffrey Carter
2001-06-23 19:30 ` David C. Hoos, Sr.
2001-06-23 22:34   ` Jeffrey Carter
2001-06-25 10:19   ` Karl Ran
replies disabled

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