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!postnews.google.com!v23g2000pro.googlegroups.com!not-for-mail From: belteshazzar Newsgroups: comp.lang.ada Subject: Re: Unconstrained Arrays Date: Mon, 16 Mar 2009 19:58:28 -0700 (PDT) Organization: http://groups.google.com Message-ID: <0caa9cf8-0620-4544-9b2c-2c9f24142b7f@v23g2000pro.googlegroups.com> References: <1a8008fb-c840-45bc-824c-d10eec9fe569@d36g2000prf.googlegroups.com> NNTP-Posting-Host: 203.36.107.146 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1237258708 23906 127.0.0.1 (17 Mar 2009 02:58:28 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 17 Mar 2009 02:58:28 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v23g2000pro.googlegroups.com; posting-host=203.36.107.146; posting-account=SuaatgoAAADZMrKGiLdPOjCBBS4KZzVT User-Agent: G2/1.0 X-HTTP-Via: 1.1 SRV021 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30),gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:4152 Date: 2009-03-16T19:58:28-07:00 List-Id: On Mar 17, 11:49=A0am, "Jeffrey R. Carter" wrote: > belteshazzar wrote: > > I have a program that uses a lot of different sized arrays and passed > > into math functions. So I'm using an unconstrained array type. The > > problem that I have is that I'm not allowed to use "new" this means > > that I have to use pools (which I can't because to intantiate a pool I > > have to constrain the array type) or allocated the arrays on the > > stack. Allocating the arrays on the stack is fine, BUT it means that i > > have to use array initializers so that they remain unconstrained > > rather than becoming an anonomous contrained type that can no longer > > be passed to my math functions. > > I'm not clear what you're talking about. You can pass a constrained subty= pe to a > subprogram that takes a parameter of an unconstrained array type. > > For example, String is an unconstrained array type. If we have > > function F (S : in String) return Natural; > > V : String (1 .. 10); > C : Natural; > > then it's perfectly legal to call F with V as its actual parameter: > > C :=3D F (S); > > > Also, and the main point of my post, I've found that I can place the > > unconstrained array inside a record with a distriminant and this seems > > to solve all our problems. We don't have to use array initialisers and > > we can get pointers to aliased objects that can be easily passed to > > the math functions. > > Here is your problem. There should be no reason to pass explicit pointers= to > these functions. Your best solution is to rewrite or change your library. > > -- > Jeff Carter > "Drown in a vat of whiskey. Death, where is thy sting?" > Never Give a Sucker an Even Break > 106 As we have very large array's we're using something like: 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); V : Unconstrained_Array :=3D (1 .. 10_000 =3D> 0); V_Ptr : Unconstrained_Array_Ptr :=3D Unconstrained_Array'unchecked_Access F (V_Ptr); Note the use of the array intialiaser, if this isn't used then the pointer is no longer compatible.