comp.lang.ada
 help / color / mirror / Atom feed
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)?
Date: 29 Sep 92 16:54:39 GMT	[thread overview]
Message-ID: <1992Sep29.165439.28862@aplcen.apl.jhu.edu> (raw)

In <YOUNG.92Sep29101112@kuwait.gdfwc3> 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

             reply	other threads:[~1992-09-29 16:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-09-29 16:54 jvnc.net!darwin.sura.net!jhunix.hcf.jhu.edu!aplcen.apl.jhu.edu!ddsdx2.jhu [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-09-29 18:33 Declaring Arrays of Bits (how)? Bob Kitzberger
1992-09-29 17:07 Mark A Biggar
1992-09-29 16:11 agate!spool.mu.edu!sdd.hp.com!cs.utexas.edu!sun-barr!west.West.Sun.COM!cr
replies disabled

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