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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5b3aa4bc9027f04e X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!j18g2000prm.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Unconstrained Arrays Date: Fri, 20 Mar 2009 08:45:46 -0700 (PDT) Organization: http://groups.google.com Message-ID: 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: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1237563946 13690 127.0.0.1 (20 Mar 2009 15:45:46 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 20 Mar 2009 15:45:46 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: j18g2000prm.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5176 Date: 2009-03-20T08:45:46-07:00 List-Id: 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). 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 := 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