From: "Richard Charts" <richard.charts@gmail.com>
Subject: Size of objects in records with an array.
Date: 24 Oct 2006 10:48:58 -0700
Date: 2006-10-24T10:48:58-07:00 [thread overview]
Message-ID: <1161712138.465357.295460@i42g2000cwa.googlegroups.com> (raw)
So I'm having more fun with records in Ada, particularly ones that must
be of an exact form.
I have a 32 bit data item I'd like to access the individual bits for.
My initial way was the 1st blurb below. It works but reality slapped
me in the face when I realized I needed to access the bits either like
an array or with some way to loop through the bits.
So I tried the bottom way, but it says the size is incorrect. Is there
a way to make this work, or am I stuck looping and bit shifting a 32
bit item?
Thanks.
-------------------------------------------------
type Data_Msg is
record
A429 : Interfaces.Unsigned_8;
Bit9 : Boolean;
Bit10 : Boolean;
Bit11 : Boolean;
Bit12 : Boolean;
Bit13 : Boolean;
Bit14 : Boolean;
Bit15 : Boolean;
Bit16 : Boolean;
Bit17 : Boolean;
Bit18 : Boolean;
Bit19 : Boolean;
Bit20 : Boolean;
Bit21 : Boolean;
Bit22 : Boolean;
Bit23 : Boolean;
Bit24 : Boolean;
Bit25 : Boolean;
Bit26 : Boolean;
Bit27 : Boolean;
Bit28 : Boolean;
Bit29 : Boolean;
Bit30 : Boolean;
Bit31 : Boolean;
Bit32 : Boolean;
end record;
for Data_Msg use
record
A429 at 0 range 0..7;
Bit9 at 1 range 0..0;
Bit10 at 1 range 1..1;
Bit11 at 1 range 2..2;
Bit12 at 1 range 3..3;
Bit13 at 1 range 4..4;
Bit14 at 1 range 5..5;
Bit15 at 1 range 6..6;
Bit16 at 1 range 7..7;
Bit17 at 2 range 0..0;
Bit18 at 2 range 1..1;
Bit19 at 2 range 2..2;
Bit20 at 2 range 3..3;
Bit21 at 2 range 4..4;
Bit22 at 2 range 5..5;
Bit23 at 2 range 6..6;
Bit24 at 2 range 7..7;
Bit25 at 3 range 0..0;
Bit26 at 3 range 1..1;
Bit27 at 3 range 2..2;
Bit28 at 3 range 3..3;
Bit29 at 3 range 4..4;
Bit30 at 3 range 5..5;
Bit31 at 3 range 6..6;
Bit32 at 3 range 7..7;
end record;
for Data_Msg'size use (8 * 4);
--------------------------------------------------
But I want to use this:
--------------------------------------------------
type Bit_Array is array ( Natural range 8..31)
of boolean;
type Data_Msg is
record
A429 : Interfaces.Unsigned_8;
Bit_Arr : Bit_Array := (others => false);
end record;
for Data_Msg use
record
A429 at 0 range 0..7;
Bit_Arr at 1 range 0..23;
end record;
for Data_Msg'size use (8 * 4);
next reply other threads:[~2006-10-24 17:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-24 17:48 Richard Charts [this message]
2006-10-24 17:56 ` Size of objects in records with an array Robert A Duff
2006-10-24 18:06 ` Richard Charts
2006-10-24 21:02 ` Adam Beneschan
2006-10-26 23:53 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox