comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@bix.com
Subject: Re: Flags in Ada?
Date: 26 Oct 1994 03:19:57 GMT
Date: 1994-10-26T03:19:57+00:00	[thread overview]
Message-ID: <38khst$hn3@news.delphi.com> (raw)

>  type Permission_Type is
>     (Owner_Read, Owner_Write, Owner_Execute,
>      Group_Read, Group_Write, Group_Execute,
>      World_Read, World_Write, World_Execute);
>
>     -- These are the "bit names"
>
>  type Permission_Set_Type is array (Permission) of Boolean;
>  pragma Pack (Permission_Set_Type);
   -- and a rep clause to say just where these 9 bits fit? ;)

or

  type Line_Statuses is record
    Data_Ready   :boolean;
    Over_Run     :boolean;
    Parity_Error :boolean;
    Framing_Error:boolean;
    Break        :boolean;
    Transmitter_Holding_Register_Empty:boolean;
    Transmitter_Shift_Register_Empty  :boolean;
  end record;
  for Line_Statuses use record
    Data_Ready    at 0 range  0 .. 0;
    Over_Run      at 0 range  1 .. 1;
    Parity_Error  at 0 range  2 .. 2;
    Framing_Error at 0 range  3 .. 3;
    Break         at 0 range  4 .. 4;
    Transmitter_Holding_Register_Empty at 0 range 5 .. 5;
    Transmitter_Shift_Register_Empty   at 0 range 6 .. 6;
  end record;
  for Line_Statuses'size use 8;

In the Permissions example all the flags are homogenous - all 'OK or
DENIED' of some permission.  So
  Current_Permissions := (Permission_Type => False);
is a reasonable thing to say.  But in the UART example they have
quite different meanings (Data_Ready is a register status, Break
a line status, Parity_Error a data status) and normal values
(Parity_Error is much less often True than Data_Ready).
And though you might well wish to say
  Running_Status.Parity_Error
    :=Running_Status.Parity_Error or Latest_Status.Parity_Error;
it's unlikely you would want
  Running_Status.Data_Ready
    := Running_Status.Data_Ready or Latest_Status.Data_Ready;
so you would not say
  Running_Status:=Running_Status or Latest_Status;
You might of course mix the two styles - put Over_Run, Parity_Error,
and Framing_Error into a three component packed boolean vector a la
Permissions because they are similar to one another, and include
that bit vector along with Data_Ready, Break, and the Transmitter
statuses in a record a la Line_Statuses;



         reply	other threads:[~1994-10-26  3:19 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 [this message]
1994-10-26  9:59     ` David Emery
1994-10-26 22:32       ` Robert Dewar
1994-10-27 13:24         ` Norman H. Cohen
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