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,FREEMAIL_FROM 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 Path: g2news2.google.com!postnews.google.com!c36g2000yqn.googlegroups.com!not-for-mail From: sjw Newsgroups: comp.lang.ada Subject: Re: Unconstrained Arrays Date: Wed, 25 Mar 2009 14:11:57 -0700 (PDT) Organization: http://groups.google.com Message-ID: <4c7128dd-085c-48b0-948f-401fcd64c2a4@c36g2000yqn.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: 82.20.239.213 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1238015518 16681 127.0.0.1 (25 Mar 2009 21:11:58 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 25 Mar 2009 21:11:58 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c36g2000yqn.googlegroups.com; posting-host=82.20.239.213; posting-account=_RXWmAoAAADQS3ojtLFDmTNJCT0N2R4U User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_6; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1,gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:5282 Date: 2009-03-25T14:11:57-07:00 List-Id: On Mar 20, 11:40=A0am, Jean-Pierre Rosen wrote: > sjw a =E9crit :> 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. > > Here is an example: > > procedure essai is > =A0 =A0type Acc is access all String; > =A0 =A0V : Acc; > =A0 =A0S1 : aliased String :=3D "abcd"; > =A0 =A0S2 : aliased String (1..4); > begin > =A0 =A0V :=3D S1'Access; > =A0 =A0V :=3D S2'Access; > end; > > And this is what GNAT says: > > essai.adb:5:04: warning: aliased object has explicit bounds > essai.adb:5:04: warning: declare without bounds (and with explicit > initialization) > essai.adb:5:04: warning: for use with unconstrained access > essai.adb:8:09: object subtype must statically match designated subtype > > The message is pretty explicit. The underlying reason has to do with > dope vectors (i.e. how the bounds of an array are attached to the > array). It might be different, depending on whether the array is > /declared/ constrained or not (S1 is declared unconstrained, although > constrained by initialization). > > For example, in the constrained case, the array might include a pointer > to a structure that describes the subtype, while in the unconstrained > case, the array might keep the bounds with the data. Therefore, a > pointer to a constrained array is incompatible with a pointer to an > unconstrained array. That makes so much sense! I think my brain freezes when I see the compiler quoting rules about statically matching, so I just remember the first 2 lines of the message (as you say, pretty explicit) and pass over the reason why in the last 2 lines. After all, GNAT is much more likely to be right than I am.