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 Path: g2news1.google.com!news1.google.com!postnews.google.com!w35g2000yqm.googlegroups.com!not-for-mail From: christoph.grein@eurocopter.com Newsgroups: comp.lang.ada Subject: Re: Unconstrained Arrays Date: Fri, 20 Mar 2009 05:15:57 -0700 (PDT) Organization: http://groups.google.com Message-ID: <6337b84b-4696-48cd-8016-e33e2456c6fa@w35g2000yqm.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: 91.13.207.237 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1237551357 5008 127.0.0.1 (20 Mar 2009 12:15:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 20 Mar 2009 12:15:57 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w35g2000yqm.googlegroups.com; posting-host=91.13.207.237; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:4204 Date: 2009-03-20T05:15:57-07:00 List-Id: On 20 Mrz., 07:45, sjw wrote: > On Mar 20, 1:53=A0am, "Peter C. Chapin" wrote: > > > > > belteshazzar wrote innews:386b0e00-a1c6-4c5f-= adf7-89b8543d0e2d@c11g2000yqj.googlegroups.com: > > > > Unfortuantely this is an optimisation and actually doesn't occur with > > > optimisation off. (I just ran a test program). I'm told that due to > > > the significant performance hit of the array initialisers when > > > optimisation is turned off we can't use that. > > > Are those initializers actually necessary? > > > type Unconstrained_Array is array(Integer range <>) of Integer; > > > My_Array : Unconstrained_Array(-10_000 .. 10_000); > > > In the above the array is uninitialized. Yes, you have to provide > > constraints, but you don't have to initialize the array here (obviously > > you'll need to do so eventually... perhaps as part of your algorithm). = The > > code you showed use an array aggregate to initialize the array... the > > constraints where taken from the initializer. However, there are other = ways > > to specify the constraints. > > 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. type Unconstrained_Array is array ( Integer range <> ) of Integer; type Unconstrained_Array_Pointer is access all Unconstrained_Array; procedure F (S : in Unconstrained_Array_Pointer); With the above declarations, the following is illegal: V : aliased Unconstrained_Array (1 .. 10_000); V_Ptr: Unconstrained_Array_Ptr :=3D V'[Unchecked_]Access because V is nominally constrained and the pointer is to nominally unconstrained objects only. Thus you have to use V : aliased Unconstrained_Array :=3D (1 .. 10_000 =3D> 0); V_Ptr: Unconstrained_Array_Ptr :=3D V'[Unchecked_]Access Now V is nominally unconstrained, its subtype however is constrained. The corresponding paragraphs in the RM are admittedly a bit complicated. See http://www.christ-usch-grein.homepage.t-online.de/AdaMagica/ThickThin.html But as was explained to you, you do not need pointers to have call by reference. The Ada RM specifies exactly for which kind of types you can rely on call be copy vs call be reference and for which types it remains unspecified. For array as yours, it's unspecified - this is because the compile can then choose the best method. E.g. for a packed boolean array that fits into a register, call by copy will normally be used for all modes, for all longer array call be reference for all modes will be used. There is the famous Robert Dewar rule that no decent compiler does silly things - and doing a copy of a 10_000 element array surely is complete nonsense! Thus use the following and all will be well if you have a decent compiler. If not, dump it into the bin and complain at the manufacturer! procedure F (S: in Unconstrained_Array); V: Unconstrained_Array (-10_000 .. -1); F (V); -- call by reference with any decent compiler