comp.lang.ada
 help / color / mirror / Atom feed
From: dewarr@my-dejanews.com
Subject: Re: unconstrained array clarification
Date: 1998/09/19
Date: 1998-09-19T00:00:00+00:00	[thread overview]
Message-ID: <6u0e9t$gj0$1@nnrp1.dejanews.com> (raw)
In-Reply-To: WishList-1809982255060001@a17.phoenix-14.goodnet.com

In article <WishList-1809982255060001@a17.phoenix-14.goodnet.com>,
  WishList@2600.com (Technobabble) 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
> type xyz_array_pointer is access xyz_array;
> 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?
>
> 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
>
> now I want to loop:
>
> for I in This.XYZ(1)'RANGE
>      loop
>       ..........
>
> ???? Will this work ???  Is the syntax totally incorrect ???
>
> help !!!
>
> Richmond



One useful rule for you at this stage is NEVER EVER use the
access attribute. It is for specialized uses, but should
hardly be used at all in normal programming. If you feel
the urge to use it at this level, you have not got the
proper semantic feel for Ada, but are trying instead to
write C in Ada, much as a Fortran-66 programmer might end
up writing lots of gotos in Ada.

Just use the rule for yourself that Ada does not have an
access attribute, and figure out how to solve your problem,
you will learn much faster that way.

Then when you really understand why the access attribute is
almost never used, you will be ready to learn about the rare
cases in which its use is justified.

By the way, your example code contains no discriminants,
so talking about whether your records are constrained or
unconstrained is completely wrong. If there are no
discriminants around, then of course all your records
are constrained.

It is VERY important to get the terminology right here. Go
back to Barnes, and make sure you understand these terms!


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum




  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 ` dewarr [this message]
1998-09-19  0:00 ` Tucker Taft
1998-09-19  0:00   ` Technobabble
1998-09-19  0:00     ` dewarr
1998-09-22  0:00     ` Robert I. Eachus
replies disabled

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