comp.lang.ada
 help / color / mirror / Atom feed
* Re: Beware: Rep spec on an enumeration type clause
@ 1997-12-12  0:00 Franco Mazzanti
       [not found] ` <34912418.13716044@news.geccs.gecm.com>
  1997-12-12  0:00 ` Ken Garlington
  0 siblings, 2 replies; 6+ messages in thread
From: Franco Mazzanti @ 1997-12-12  0:00 UTC (permalink / raw)



Rakesh Malhotra wrote:

> We work on safety critical projects.  And if we have a safety critical
> bit of code that defines and uses an enumeration then we use the rep
> clause to provide more than 1 bit separation between adjacent values in
> the enumeration.  That way if 1 bit got corrupted the value could not
> become some other legal value.
>
> Hence type SIGNAL_TYPE is (RED, GREEN);
> for SIGNAL_TYPE use (RED => 16#00#, GREEN => 16#03#);
>
> So if a signal was supposed to be RED, with just a 1 bit corruption it
> could never become GREEN.  Obviously we have these kinds of enum's and
> rep clauses all over the code space, and they are used in arrays to
> index etc etc.    An even worse example (from the coder's point of view)
> is that we create our own BOOLEAN_TYPE with states defined as TRUE_STATE
> and FALSE_STATE ; then give both true and false explicit values; and
> then test for those in "if" statements etc :)  Pretty horrible eh ?
>
> --
> Rakesh.


Since the program behaviour when some invalid object is encountered is
highly
implementation dependent, this approach seems really dangerous to me ...
For example, for example, the following program, compiled with GNAT v.3.09
happily (and legally) produces the output:

> I is neither AA, BB or CC
> I is  AA or BB

with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   type T is (AA, BB, CC);
   for T use (AA => -1, BB => 10, CC => 20);
   I:T;                -- not initialised
   V:array (T) of Integer;
begin
  if not I'Valid then
     Put_Line("I is neither AA, BB or CC ");
  end if;
   case I is
      when AA..BB =>  -- can be selected if I is invalid
        Put_line("I is AA or BB");
      when CC =>  -- can be selected if I is invalid
        Put_line("I is CC");
         V(CC) := 0;
   end case;
end Main;

------------------------------------------------------------
   Franco Mazzanti
   Istituto di Elaborazione della Informazione
   mazzanti@iei.pi.cnr.it
------------------------------------------------------------





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1997-12-19  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-12  0:00 Beware: Rep spec on an enumeration type clause Franco Mazzanti
     [not found] ` <34912418.13716044@news.geccs.gecm.com>
1997-12-12  0:00   ` Ken Garlington
1997-12-12  0:00   ` Matthew Heaney
     [not found]     ` <349e19ec.16536708@news.geccs.gecm.com>
1997-12-18  0:00       ` Matthew Heaney
     [not found]         ` <349a4134.5569381@news.geccs.gecm.com>
1997-12-19  0:00           ` Matthew Heaney
1997-12-12  0:00 ` Ken Garlington

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