From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,203d1f2317947ef5 X-Google-Attributes: gid103376,public From: Mike Bishop Subject: Re: others clause Date: 1996/08/30 Message-ID: <3227AAA6.67C9@ghgcorp.com>#1/1 X-Deja-AN: 177554899 references: content-type: text/plain; charset=us-ascii organization: GHG Internet Services mime-version: 1.0 reply-to: mbishop@ghgcorp.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.0 (Win95; I) Date: 1996-08-30T00:00:00+00:00 List-Id: 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/