comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@cs.nyu.edu (Robert Dewar)
Subject: Re: others clause
Date: 1996/08/31
Date: 1996-08-31T00:00:00+00:00	[thread overview]
Message-ID: <dewar.841529126@schonberg> (raw)
In-Reply-To: INFO-ADA%96082914113458@LISTSERV.NODAK.EDU


iChris asks

  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;

first of all you do not mean erroneous, please be careful with this
terminology. Erroneous is a technical term in Ada with very specific
meaning and it is confusing to use it in its non-tecynical sense.
You mean illegal, another technical term, which should also be used
only for its exact purpose.l

This certainly is not illegal according to the definition in the RM,
which I assume is clear (if you are asking about how to read this
in the RM, then reask, it's straightforward).

SO I assume this is a "why is Ada designed this way" type question?

In fact I think it is highly desirable to allow a redundant others
branch. Basically the others says, do this if I have not specifically
taken care of it otherwise.

In some cases, it may not be at all clear whether you have taken care
of all branches, or may depend on constants that are configurable, and
you do not want changing the configurable constant to mean that you have
to go around chnaging case statements around the place.

I think a compiler warning is *possibly* advisable/acceptable, but I
would need to think more about this.

Incidentally, in GNAT, a common usage is

	when others =>
	   pragma Assert (False); null;

to generally note that you did not expect to get into the other section,
either because all cases were covered, or because the logic says you should
not be here.





  parent reply	other threads:[~1996-08-31  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
1996-08-31  0:00   ` Robert A Duff
1996-09-02  0:00   ` Geert Bosch
1996-09-03  0:00     ` Robert Dewar
1996-09-02  0:00   ` Brian Rogoff
1996-09-03  0:00   ` Adam Beneschan
1996-08-31  0:00 ` Robert Dewar [this message]
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