TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Tucker Taft <[log in to unmask]>
Reply To:
Tucker Taft <[log in to unmask]>
Date:
Mon, 15 Nov 1999 12:32:47 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (58 lines)
Mike Smith wrote:
>
> Hi all,
>
> I'd appreciate your help in answering the following question:
>
> Is it unsafe to rename a type using an unconstrained subtype?

I can't quite imagine what you mean by this.  Could you give an example.
Perhaps you mean:

   subtype Uncon is T'Base;

I wouldn't call that "renaming".  This is declaring an unconstrained
subtype.

>
> I've read in Barnes 2nd Ed (page 333) that range checking is disabled for
> unconstrained subtypes, so this would seem to imply that only constrained
> subtypes are really safe.

You may have misunderstood this.  There is no specific range implied,
but there is still an overflow check.  The requirement is that the
generated code must either get the correct answer, or raise Constraint_Error
due to an overflow.  With a constrained subtype, each time you store the
result in a variable, it will be rechecked to see whether it is in
the specific range.  With an unconstrained subtype, storing the
result in an unconstrained variable will only result in an exception
if the result cannot be represented without overflow.  Effectively the
range constraint is determined by the "physical" range of the variable's
memory cell/register, rather than by some constraint specified by the
programmer.


> ...I'm primarily interested in where, if at all, a
> range check would occur.  My first assumption was that a check would occur
> if an object of that subtype was passed as a parameter, but Barnes' example
> would seem to rule that out.

There are no range checks per se, but there are overflow checks, which
amount to basically the same thing if the range matches the physical
range.
>
> If I must use a constrained subtype, then so be it, but I'll miss the
> convenience of leaving off the seemingly redundant constraint.

Again you have lost me by mentioning a "redundant" constraint.
Perhaps some examples would help explain the issue.

>
> Thanks,
> Mike

--
-Tucker Taft   [log in to unmask]   http://www.averstar.com/~stt/
Technical Director, Distributed IT Solutions  (www.averstar.com/tools)
AverStar (formerly Intermetrics, Inc.)   Burlington, MA  USA

ATOM RSS1 RSS2