From: belteshazzar <gbelteshazzar@gmail.com>
Subject: Re: Unconstrained Arrays
Date: Mon, 23 Mar 2009 01:26:18 -0700 (PDT)
Date: 2009-03-23T01:26:18-07:00 [thread overview]
Message-ID: <7cb5e12c-242f-4a07-9594-c0ca7a7e07d9@u9g2000pre.googlegroups.com> (raw)
In-Reply-To: f926a0e7-b0c7-49bb-b67c-65caeff89a9e@j18g2000prm.googlegroups.com
On Mar 21, 1:45 am, Adam Beneschan <a...@irvine.com> wrote:
> On Mar 19, 11:45 pm, sjw <simon.j.wri...@mac.com> wrote:
>
> > There is a deep language-lawyerly reason (which I don't understand)
> > why an array like your My_Array can't be aliased (at any rate in
> > Ada95); you have to use the initialize-with-aggregate approach.
> > Perhaps that's what leads to the initialize-with-aggregate style.
>
> I don't remember what exact rules make this illegal (I could look them
> up, but I don't feel like it right now; it has to do with nominal
> subtypes). But here's the issue:
>
> Say you declare an array
>
> type Unconstrained_Array is array (Natural range <>) of Integer;
> type Unconstrained_Array_P is access Unconstrained_Array;
> Arr : aliased Unconstrained_Array (1..100);
>
> When you have an object of type Unconstrained_Array_P, it points to a
> specific object with specific bounds, and the code has to have a way
> to get the bounds from the pointer. In some Ada implementations, the
> way this works is that the bounds of the array are stored in memory
> followed by the array data. This worked fine in Ada 83, where the
> only way you could get an Unconstrained_Array_P was with an
> allocator. In Ada 95, we have 'Access and "aliased", so we have to
> consider the possibility that someone would want to use the 'Access of
> Arr as an Unconstrained_Array_P. In those Ada implementations, this
> would mean that the compiler would have to store the bounds of every
> aliased array in front of the array data, including those that are
> record components, just in case some other part of the code somewhere
> else in the program decided to use the 'Access of it as an
> Unconstrained_Array_P. This was deemed to be too much overhead, so as
> a compromise the language rules were engineered so that in this case,
>
> Arr : aliased Unconstrained_Array (1..100);
>
> 'Access could not be used as an Unconstrained_Array_P, while in this
> case:
>
> Arr : aliased Unconstrained_Array := <initial expression>
>
> it could (and the bounds would have to be stored in memory). So that
> way, the programmer has a choice.
>
> I'm sure that things were done in this way to avoid adding too much
> extra language syntax. If I had been responsible for designing the
> Ada syntax, the language would have already died a horrible death and
> we wouldn't even be having this discussion; nevertheless, I might have
> suggested something like
>
> Arr : aliased {unconstrained_access_ok} Unconstrained_Array
> (1..100);
>
> with attribute names (that aren't added to the list of reserved words)
> in braces to tell the compiler things whether it's legal to convert
> the 'Access to an unconstrained array pointer.
>
> Hope this helps explain things. In any case, I strongly agree with
> everyone else that using pointers in the OP's particular situation is
> the wrong approach, and there shouldn't be any reason for it except
> perhaps to work around a poor compiler implementation.
>
> -- Adam
I have to say that in my opinion this is a crappy language feature,
unconstrained and constrained arrays of the same type should be
interchangeable when declared on the stack. I realise that Ada05
allows the <> initialiser but i see that as a pretty poor solution.
we've converted our system to not use handles and it is so much
cleaner. the only problem is that for no-optimisation compilation
(used for debugging) it seems that the compiler is copying the large
arrays around. personally i don't see that as a problem.
thanks for everyone's help.
next prev parent reply other threads:[~2009-03-23 8:26 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-17 0:59 Unconstrained Arrays belteshazzar
2009-03-17 1:49 ` Jeffrey R. Carter
2009-03-17 2:58 ` belteshazzar
2009-03-17 4:15 ` Jeffrey Creem
2009-03-17 5:20 ` Jeffrey R. Carter
2009-03-17 17:56 ` Jeffrey R. Carter
2009-03-17 23:10 ` belteshazzar
2009-03-18 18:31 ` Jeffrey R. Carter
2009-03-20 1:53 ` Peter C. Chapin
2009-03-20 6:45 ` sjw
2009-03-20 9:46 ` Jacob Sparre Andersen
2009-03-20 11:40 ` Jean-Pierre Rosen
2009-03-25 21:11 ` sjw
2009-03-25 22:30 ` Robert A Duff
2009-03-25 23:28 ` Randy Brukardt
2009-03-26 0:03 ` Jeffrey R. Carter
2009-03-26 1:00 ` Robert A Duff
2009-03-20 12:15 ` christoph.grein
2009-03-20 15:45 ` Adam Beneschan
2009-03-23 8:26 ` belteshazzar [this message]
2009-03-25 21:21 ` sjw
2009-03-25 22:03 ` Adam Beneschan
2009-03-26 1:32 ` tmoran
2009-03-27 8:39 ` Jean-Pierre Rosen
2009-03-27 20:07 ` sjw
2009-03-29 16:24 ` sjw
2009-03-27 11:57 ` Gautier
2009-03-17 15:33 ` Adam Beneschan
2009-03-17 23:00 ` belteshazzar
2009-03-17 20:14 ` anon
-- strict thread matches above, loose matches on Subject: below --
2001-12-11 17:17 Unconstrained arrays Michael Unverzagt
2001-12-11 18:22 ` Stephen Leake
2001-12-11 18:24 ` Mark Lundquist
1993-08-15 5:01 Alex Blakemore
1993-08-13 21:08 J. Craig Heberle
1993-08-13 12:34 Paul Durbin
1993-08-12 21:23 Robert Dewar
1993-08-12 19:25 Wes Groleau x1240 C73-8
1993-08-12 17:27 agate!howland.reston.ans.net!math.ohio-state.edu!magnus.acs.ohio-state.ed
1993-08-12 16:26 Mark A Biggar
1993-08-12 16:00 Dave Collar d x7468
1993-08-12 15:28 Robert I. Eachus
1993-08-12 15:00 Robert Dewar
1993-08-12 13:03 Raymond Blaak
1993-08-12 12:14 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.
1993-08-12 12:03 cis.ohio-state.edu!pacific.mps.ohio-state.edu!math.ohio-state.edu!magnus.
1993-08-11 23:42 Kenneth Anderson
1993-08-11 23:40 cis.ohio-state.edu!math.ohio-state.edu!cs.utexas.edu!swrinde!menudo.uh.ed
1993-08-11 22:29 Kenneth Anderson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox