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: a07f3367d7,e276c1ed16429c03 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Vinzent Hoefler" Newsgroups: comp.lang.ada Subject: Re: Ada is getting more popular! Date: Thu, 14 Oct 2010 00:34:04 +0200 Message-ID: References: <020ea727-e8e9-4d0d-8c5f-b8ad907fc3c9@u10g2000yqk.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: individual.net 6hfbKX5L8VKrM2yOVh4qdgMUMII3kERukci9NHxSB81lt7VIYF Cancel-Lock: sha1:GaPyWWkYhDELLyxJ3A2PLrSeCMY= User-Agent: Opera Mail/10.62 (Win32) Xref: g2news2.google.com comp.lang.ada:15491 Date: 2010-10-14T00:34:04+02:00 List-Id: On Wed, 13 Oct 2010 23:53:14 +0200, ramon_garcia wrote: > I have a record with an array member constrained. I want to obtain an > unconstrained accesss, because I want to return it in a procedure. I > want to return an access, because returning an array implies a copy. Huh? Since when do "out" parameters imply a copy? > And I want the caller to get the bounds of the returned access at > runtime. I don't understand that. Either you are creating the array dynamically, then getting an access to it should not be a problem or the caller already knows the bounds. > type buffer is array(Natural range<>) of Unsigned_8; > type buffer_access is access all buffer; > > type t is record > data: buffer(1..4); There an "aliased" would be missing. > end record; > > a_t: t := .....; > > abuf_access := a_t.data'Unrestricted_Access; > > Note that this has two dependencies with GNAT: > - Access to arrays use double pointers. So in the obtained access one > can obtain the bounds correctly, with abuf_access'First, > abuf_access'Last. This is not GNAT specific. An access type is guaranteed to work correctly here. An *address* OTOH may not, but that's different anyway. > - The attribute Unrestricted_Access. > > I cannot understand why a procedure that expects an unconstrained > array can be passed a constrained one, Because every array is constrained at the point of the call. There are no unconstrained array objects. > and it is not possible to get > an access to an unconstrained array from a constrained one. It is. But not if it's explicitly constrained (by index constraints). Unfortunately, this is the only way to do it inside a record. Vinzent. -- There is no signature.