comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: unconstrained array clarification
Date: 1998/09/19
Date: 1998-09-19T00:00:00+00:00	[thread overview]
Message-ID: <EzJ5up.JLu.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: WishList-1809982255060001@a17.phoenix-14.goodnet.com

Technobabble (WishList@2600.com) wrote:

: Ok, thanks !  Now what if all I have is an unconstrained array type like this:

: type xyz_array is array (integer <>) of integer;   -- this is it
                                  ^^ insert "range"

: type xyz_array_pointer is access xyz_array;
                                  ^^ insert "all" if you want to use 'Access

: type xyz_array_pointer_array is array (1..100) of xyz_array_pointer;


: type Object is
:     record
:        XYZ : xyz_array_pointer_array;    
:        abc : integer;
:     end record;


: Now I declare an Object,

: This : Object;   --  record is not constrained, legal or not?

This record *is* constrained since its type doesn't have any discriminants.
If its type did have discriminants, this would be legal if the
discriminants had defaults.
                        
: Now I want to have say a 5 element xyz_array:

: xyz5_array : xyz_array (1..5);

: and I assign my pointer

: This.XYZ(1) := xyz5_array'ACCESS;  -- address of xyz_array type is assigned

This is not legal for two reasons.  First, xyz5_array needs
to be declared "aliased".  Secondly, the "nominal subtype" of
xyz5_array must exactly match the "designated" subtype of the access
type.  Since the designated subtype is xyz_array (unconstrained),
then xyz5_array needs to have an unconstrained "nominal" subtype, as follows:

   xyz5_array : aliased xyz_array := (1..5 => 0);

This requirement for subtype matching is a bit of a pain, but using 'Access
imposes some stringent requirements on matching of representation, and
for pointers to arrays, it can matter greatly whether the nominal
subtype is constrained or unconstrained (you'll have to trust me on
this one).

: now I want to loop:

: for I in This.XYZ(1)'RANGE
:      loop 
:       ..........


: ???? Will this work ???  Is the syntax totally incorrect ???

This can be made to work, with the above changes.

It might be interesting to have some idea where you are headed
with all of this.  There might be a simpler overall solution.

: help !!!

: Richmond

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA
An AverStar Company




  reply	other threads:[~1998-09-19  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-19  0:00 unconstrained array clarification Technobabble
1998-09-19  0:00 ` Tucker Taft [this message]
1998-09-19  0:00   ` Technobabble
1998-09-19  0:00     ` dewarr
1998-09-22  0:00     ` Robert I. Eachus
1998-09-19  0:00 ` dewarr
replies disabled

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