comp.lang.ada
 help / color / mirror / Atom feed
From: Per Sandberg <per.s.sandberg@bahnhof.se>
Subject: Re: Pointer to instance of indefinite array?
Date: Wed, 13 Aug 2014 06:31:40 +0200
Date: 2014-08-13T06:31:40+02:00	[thread overview]
Message-ID: <53eaea2e$0$32377$862e30e2@ngroups.net> (raw)
In-Reply-To: <58a951df-217b-48ee-bd0b-f9953f5b622b@googlegroups.com>

Well,
The compiler uses the most appropriate method of passing parameters (by 
value or by reference) depending on the kind of object, this usually 
means that composite types is passed by reference and scalars is passed 
by value.
However your sample does compile with some small modifications:
------------------------------------------
package Test_Package is
    type Element is
       record
          ID_1 : Positive;
          ID_2 : Positive;
       end record;
    type Element_Array     is array (Positive range <>) of Element;
    type Element_Array_Ptr is access all Element_Array;
    --> Use "all" to be able to reference objects allocated on staticly 
or stack.
    procedure Do_Something_With_Array (In_Array : in Element_Array_Ptr);
end Test_Package; 	
-----------------------------
with Test_Package; use Test_Package;
procedure main is
    Test_Array : aliased Element_Array (1 .. 20);
begin
    Do_Something_With_Array (In_Array => Test_Array'Unrestricted_Access);
    --  Use Unrestricted_Access attribute to disable
    --  accessibility and aliased view checks
end main;
----------------------------
/Per

On 13.08.2014 05:06, NiGHTS wrote:
> On Tuesday, August 12, 2014 10:29:04 PM UTC-4, Shark8 wrote:
>> On 12-Aug-14 20:07, NiGHTS wrote:
>> What are you really trying to do? You can do everything you want in the
>> example w/o touching access types:
>
> On Tuesday, August 12, 2014 10:09:37 PM UTC-4, Jeffrey Carter wrote:
>> Think in Ada and get rid of the access type.
>
> Hmm. You're right. It worked! Compiler must be changing it internally to a pointer though since it would be far too inefficient to copy the entire array.
>


  parent reply	other threads:[~2014-08-13  4:31 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-13  2:07 Pointer to instance of indefinite array? NiGHTS
2014-08-13  2:09 ` Jeffrey Carter
2014-08-13  2:29 ` Shark8
2014-08-13  3:06   ` NiGHTS
2014-08-13  4:28     ` Jeffrey Carter
2014-08-13 16:06       ` NiGHTS
2014-08-13 17:43         ` Jeffrey Carter
2014-08-13 17:58         ` Shark8
2014-08-13 18:36         ` Dmitry A. Kazakov
2014-08-13  4:31     ` Per Sandberg [this message]
2014-08-13  7:47       ` Georg Bauhaus
2014-08-13  8:05         ` Egil H H
2014-08-13 15:32         ` Adam Beneschan
2014-08-14  8:03           ` Georg Bauhaus
2014-08-13 18:17       ` Niklas Holsti
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox