From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5b3aa4bc9027f04e X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!postnews.google.com!u9g2000pre.googlegroups.com!not-for-mail From: belteshazzar Newsgroups: comp.lang.ada Subject: Re: Unconstrained Arrays Date: Mon, 23 Mar 2009 01:26:18 -0700 (PDT) Organization: http://groups.google.com Message-ID: <7cb5e12c-242f-4a07-9594-c0ca7a7e07d9@u9g2000pre.googlegroups.com> References: <1a8008fb-c840-45bc-824c-d10eec9fe569@d36g2000prf.googlegroups.com> <0caa9cf8-0620-4544-9b2c-2c9f24142b7f@v23g2000pro.googlegroups.com> <386b0e00-a1c6-4c5f-adf7-89b8543d0e2d@c11g2000yqj.googlegroups.com> <46281cbb-2804-41e8-87a0-251c9060d4d1@c36g2000yqn.googlegroups.com> NNTP-Posting-Host: 121.45.145.81 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1237796778 17621 127.0.0.1 (23 Mar 2009 08:26:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 23 Mar 2009 08:26:18 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: u9g2000pre.googlegroups.com; posting-host=121.45.145.81; posting-account=SuaatgoAAADZMrKGiLdPOjCBBS4KZzVT User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:4225 Date: 2009-03-23T01:26:18-07:00 List-Id: On Mar 21, 1:45=A0am, Adam Beneschan wrote: > On Mar 19, 11:45 pm, sjw 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). =A0But here's the issue: > > Say you declare an array > > =A0 type Unconstrained_Array is array (Natural range <>) of Integer; > =A0 type Unconstrained_Array_P is access Unconstrained_Array; > =A0 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. =A0In some Ada implementations, the > way this works is that the bounds of the array are stored in memory > followed by the array data. =A0This worked fine in Ada 83, where the > only way you could get an Unconstrained_Array_P was with an > allocator. =A0In 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. =A0In 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. =A0This was deemed to be too much overhead, so as > a compromise the language rules were engineered so that in this case, > > =A0 Arr : aliased Unconstrained_Array (1..100); > > 'Access could not be used as an Unconstrained_Array_P, while in this > case: > > =A0 Arr : aliased Unconstrained_Array :=3D > > it could (and the bounds would have to be stored in memory). =A0So that > way, =A0the programmer has a choice. > > I'm sure that things were done in this way to avoid adding too much > extra language syntax. =A0If 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 > > =A0 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. =A0In 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. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- 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.