comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: Flags in Ada?
Date: 27 Oct 1994 13:24:24 GMT
Date: 1994-10-27T13:24:24+00:00	[thread overview]
Message-ID: <38o9m8$mo6@watnews1.watson.ibm.com> (raw)
In-Reply-To: 38mle1$e3m@gnat.cs.nyu.edu

In article <38mle1$e3m@gnat.cs.nyu.edu>, dewar@cs.nyu.edu (Robert Dewar)
writes: 
|> well to me Dave's approach seems overkill
|>
|> I really don't see the objection to a packed record.

The original question asked how to provide for logical operations among
corresponding flags in different flag sets.  Packed arrays of Booleans
provide this and packed records of Booleans do not, except with tedious
explicit programming: 

   generic
      with Op (Left, Right: Boolean) return Boolean;
   function Packed_Record_Op;

   function Packed_Record_Op
      (Left, Right: Packed_Record_Type) return Packed_Record_Type is
   begin
      return
         ( Op(Left.Component_1, Right.Component_1),
             ...,
           Op(Left.Component_N, Right.Component_N) );
   end Packed_Record_Op;

   function "and" is new Packed_Record_Op("and");
   function "or"  is new Packed_Record_Op("or");
   function "xor" is new Packed_Record_Op("xor");

   function "not" (Right: Packed_Record_Op) return Packed_Record_Op is
   begin
      return (not Right.Component_1, ..., not Right.Component_N);
   end "not";

Still, if you require explicit control over the mapping of Booleans in
such an array to specific bits in a word (for the sake of a low-level
external interface), only record representation clauses can provide them.

It is unfortunate that there is no portable way to indicate whether,as
index values increase, the positions of components in a packed array of
Booleans go from LSB to MSB or MSB to LSB.

--
Norman H. Cohen    ncohen@watson.ibm.com



  reply	other threads:[~1994-10-27 13:24 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-10-25 10:36 Flags in Ada? Andre Spiegel
1994-10-25 10:07 ` David Emery
1994-10-25 16:19 ` Norman H. Cohen
1994-10-26  3:19   ` tmoran
1994-10-26  9:59     ` David Emery
1994-10-26 22:32       ` Robert Dewar
1994-10-27 13:24         ` Norman H. Cohen [this message]
1994-10-27 15:15         ` John Volan
1994-10-31  9:29         ` David Emery
1994-10-27 22:34       ` Henry G. Baker
1994-10-26 14:33     ` Robert Dewar
1994-10-26 17:43     ` Norman H. Cohen
1994-10-26 15:54   ` Andre Spiegel
1994-10-26  0:36 ` Dale Stanbrough
1994-10-26 11:01   ` Robert Dewar
1994-10-27  8:23 ` Henri Altarac
1994-10-27 23:00   ` Robert Dewar
1994-10-31  9:32     ` David Emery
  -- strict thread matches above, loose matches on Subject: below --
1994-10-25 16:22 tmoran
1994-10-27  5:05 tmoran
1994-10-27 13:29 ` Robert Dewar
1994-10-27 17:15 ` Norman H. Cohen
1994-10-28  3:51   ` Robert Dewar
1994-10-27  5:06 tmoran
1994-10-27 13:47 ` Robert Dewar
1994-10-28  2:41   ` Tucker Taft
1994-10-30 13:31     ` Robert Dewar
1994-10-28  3:59 tmoran
1994-10-28 13:43 ` Robert Dewar
1994-10-31 14:19   ` Norman H. Cohen
1994-11-02 14:06     ` Mats Weber
1994-11-03 23:08       ` Robert Dewar
1994-11-03 11:26     ` 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