comp.lang.ada
 help / color / mirror / Atom feed
From: jvl@ocsystems.com (Joel VanLaven)
Subject: Re: Access to Unconstrained Arrays
Date: 1997/04/21
Date: 1997-04-21T00:00:00+00:00	[thread overview]
Message-ID: <1997Apr21.005646.25460@ocsystems.com> (raw)
In-Reply-To: 3357B77F.44EE@boeing.com


John Harbaugh (john.s.harbaugh2@boeing.com) wrote:
: John Harbaugh wrote:
: > 
: > When trying to pass pointers to objects of unconstrained array type, I
: > am getting confusing compiler errors.  For example:
: > 

[snipped old code]

: > List1 should be an anonymous constrained subtype of type Lists.  I was
: > under the impression that subtypes are simply a subset of their base
: > type.  Is this not the case for constrained subtypes of unconstrained
: > types?
: > 
: > Thanks in advance for any who may respond.
: > 
: >    - John


: How embarrasing, please excuse the mangled code.  What I meant to show
: was:

:  procedure Main is
:     type Lists is array(Natural range <>) of Integer;
:     type Lists_Ptrs is access all Lists;
:  
:     procedure Do_Something(To : in Lists_Ptrs) is separate;
:  
:     List1 : aliased Lists(1..4) := (1,2,3,4);
:     List2 : aliased Lists       := (1,2,3,4);

:     Ptr : Lists_Ptrs;
:  
:  begin
:     Ptr := List1'access;
:     Do_Something(To => Ptr);  -- Compilation Error.  Why?
:     Ptr := List2'access;
:     Do_Something(To => Ptr);  -- No problemo!!!
:  end Main;

: Apparently, the problem is that Lists(1..4) is a different subtype
: indication than Lists.

  I agree with you that this code ought to compile.  In fact, our
compiler does compile your code without error or warning.  Attempting
to resolve the conflict between this fact and Robert Dewar's comments,
I did a bit of Reference Manual snooping and found the following:

RM95: 3.10(14)
  "The first subtype of a type defined by an access_type_definition or an
access_to_object_definition is unconstrained if the designated subtype is
an unconstrained array or discriminated type; otherwise it is constrained."

  So, the first subtype of Lists_Ptrs is an unconstrained access subtype.

RM95 3.10(15)
  "An access value satisfies a composite_constraint of an access subtype
if it equals the null value of its type or if it designates an object
whose value satisfies the constraint."

  So, don't both list1'access and list2'access satisfy the (non-existant)
composite_constraint of the first subtype of lists_ptr?  Making both
assignments valid, right?

  If someone says not, could you explain why not?  (hopefully chapter and
verse of the rm :)
-- 
-- Joel VanLaven




  parent reply	other threads:[~1997-04-21  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-16  0:00 Access to Unconstrained Arrays John Harbaugh
1997-04-18  0:00 ` Joel VanLaven
1997-04-20  0:00   ` Robert Dewar
1997-04-18  0:00 ` Robert Dewar
1997-04-18  0:00 ` John Harbaugh
1997-04-20  0:00   ` Robert Dewar
1997-04-21  0:00   ` Joel VanLaven [this message]
1997-04-21  0:00     ` Robert A Duff
1997-04-23  0:00       ` Robert Dewar
replies disabled

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