From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 29 Sep 92 16:54:39 GMT From: jvnc.net!darwin.sura.net!jhunix.hcf.jhu.edu!aplcen.apl.jhu.edu!ddsdx2.jhu apl.edu!dlc@rutgers.edu (Dave Collard x7468) Subject: Re: Declaring Arrays of Bits (how)? Message-ID: <1992Sep29.165439.28862@aplcen.apl.jhu.edu> List-Id: In young@gdfwc3 (Mark Young) writes: >I am trying to declare arrays of bits in Ada. Here's my attempt: >type Array_Range_Type is range 1..128; >type Bit_Type is (OFF, ON); >for Bit_Type use (OFF => 0, ON => 1); >for Bit_Type'size use 1; >type Bit_Array_Type is array (Array_Range_Type) of Bit_Type; -- Add this line: pragma Pack(Bit_Array_Type); -- and you will find that Bit_Array_Type objects will be stored as -- you originally expected. The compiler chose the most efficient -- implementation of Bit_Array_Type, as it is allowed to do. -- However, see below for a better way to do what you are probably -- really trying to do. >Bit_Array : Bit_Array_Type; -- I believe that you really want a packed array of boolean which -- is how I often represent bits: type Array_Range_Type is range 1..128; type Bit_Array_Type is array(Array_Range_Type) of Boolean; pragma pack(Bit_Array); -- This makes it much easier to do logical bitwise operations on -- the resulting data structure, which is usually why you want -- arrays of bits in the first place. Note that the packed boolean -- array is guaranteed to take up exactly 1 bit per boolean by -- some AI or other. --Thor dlc@ddsdx2.jhuapl.edu collard@capsrv.jhuapl.edu