comp.lang.ada
 help / color / mirror / Atom feed
From: Mike Bishop <mbishop@ghgcorp.com>
Subject: Re: others clause
Date: 1996/08/30
Date: 1996-08-30T00:00:00+00:00	[thread overview]
Message-ID: <3227AAA6.67C9@ghgcorp.com> (raw)
In-Reply-To: INFO-ADA%96082914113458@LISTSERV.NODAK.EDU


Chris Sparks wrote:
> 
> Why is the following not incorrect?
> 
> ---------------------------------------------------------------------
> procedure T is
> 
>   type Enum is (A, B, C, D, E, F);
> 
>   T1 : Enum    := Enum'First;
>   T2 : Integer := 0;
> 
> begin
>   case T1 is
>     when A      => null;
>     when B      => null;
>     when C      => null;
>     when D      => null;
>     when E      => null;
>     when F      => null;
>     when others => null;               --WHY ISN'T THIS ERRONEOUS?
>   end case;

According to the Ada 95 LRM, section 5.4, each value of T1 must be
covered either explicitly by a non-other discrete choice or by others.
That is the case in the above code. The LRM does not state that if all
values are covered by non-other choices, then others is not allowed. In
fact, using others is a good idea even when all values are explicitly
covered. If you add more values to the type but forget to modify the
case statement, you can still handle the new values in the others
choice.

>   case T2 is
>     when Integer'First .. -1 => null;
>     when 0                   => null;
>     when 1 .. Integer'Last   => null;
>     when others              => null;  --WHY ISN'T THIS ERRONEOUS?
>   end case;
> 
> end T;

Not only is others not erroneous here, it is required. If the type of
the case expression is root_integer or universal_integer, you must have
an others choice.

-- 
Mike Bishop         
mbishop@ghgcorp.com 
http://www.ghgcorp.com/mbishop/




  reply	other threads:[~1996-08-30  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-29  0:00 others clause Chris Sparks
1996-08-30  0:00 ` Mike Bishop [this message]
1996-08-31  0:00   ` Robert A Duff
1996-09-02  0:00   ` Brian Rogoff
1996-09-02  0:00   ` Geert Bosch
1996-09-03  0:00     ` Robert Dewar
1996-09-03  0:00   ` Adam Beneschan
1996-08-31  0:00 ` Robert Dewar
1996-09-02  0:00 ` Stephen Bull
replies disabled

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