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.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!seismo!rochester!pt.cs.cmu.edu!sei.cmu.edu!firth From: firth@sei.cmu.edu.UUCP Newsgroups: comp.lang.ada Subject: Re: single valued variables Message-ID: <871@aw.sei.cmu.edu.sei.cmu.edu> Date: Mon, 6-Apr-87 08:44:58 EST Article-I.D.: aw.871 Posted: Mon Apr 6 08:44:58 1987 Date-Received: Sat, 18-Apr-87 02:50:12 EST References: <8704031535.AA26545@ucbvax.Berkeley.EDU> Sender: netnews@sei.cmu.edu Reply-To: firth@bd.sei.cmu.edu.UUCP (PUT YOUR NAME HERE) Distribution: world Organization: Carnegie-Mellon University, SEI, Pgh, Pa List-Id: In article <8704031535.AA26545@ucbvax.Berkeley.EDU> "SVDSD::PETCHER@ti-eg.CSNET" writes: >I am not an Ada expert, so correct me if I'm wrong, but... >When one declares a variable range to be (true..true) is that not in itself a >contradiction? A variable that can have only one value is, by definition, not >a variable, but a constant. In that context, it seems a compiler should >create a constant, issue a diagnostic for any subsequent code that attempts to >change the constant, and generate no executeable code for same. I realize the >most likely place for a single-valued variable to occur would be in >instantiation of a generic, but if a generic so instantiated does not treat >single-valued variables as constants then the program is basically in error. > >Malcolm Thanks for an interesting question! First, two Ada points. It is indeed legal to constrain a subrange to a single value, and then to declare variables of that subrange. It is then legal to assign to those variables, but of course there is only one value you can assign. Indeed, the proverbial "optimising" compiler could allocate no storage for the variables, since the value in them is known. It must still do the range checks, of course. And the assignment is still legal, it just does nothing. There is no contradiction in such a subtype. It seems pretty silly written out explicitly, but recall that the bounds of a range can be dynamic, and might just happen to define a range with one (or even no) members. This could happen, for instance, during a generic instantiation. As long as the code works, there seems no reason to rule it illegal. As a more familiar analogy, consider an array with no components. We expect sort routines &c to work on such arrays, because we might generate them dynamically in the normal course of running our code. Boundary conditions should be handled even when seemingly meaningless.