comp.lang.ada
 help / color / mirror / Atom feed
From: firth@sei.cmu.edu.UUCP
Subject: Re: single valued variables
Date: Mon, 6-Apr-87 08:44:58 EST	[thread overview]
Date: Mon Apr  6 08:44:58 1987
Message-ID: <871@aw.sei.cmu.edu.sei.cmu.edu> (raw)
In-Reply-To: 8704031535.AA26545@ucbvax.Berkeley.EDU

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.

  reply	other threads:[~1987-04-06 13:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1987-04-03 12:14 single valued variables SVDSD::PETCHER@ti-eg.CSNET
1987-04-06 13:44 ` firth [this message]
1987-04-08 19:29 ` gore
  -- strict thread matches above, loose matches on Subject: below --
1987-04-07  5:26 drw
replies disabled

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