comp.lang.ada
 help / color / mirror / Atom feed
* Pointer to instance of indefinite array?
@ 2014-08-13  2:07 NiGHTS
  2014-08-13  2:09 ` Jeffrey Carter
  2014-08-13  2:29 ` Shark8
  0 siblings, 2 replies; 15+ messages in thread
From: NiGHTS @ 2014-08-13  2:07 UTC (permalink / raw)


Suppose I have a package like this...


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 Element_Array;

    procedure Do_Something_With_Array (
        In_Array : in Element_Array_Ptr
    );

end Test_Package;


In this situation I have an array of "Element" records with an unknown number of elements. The number of elements are to be defined by the user of this package and passed as a pointer to the procedure "Do_Something_With_Array".

So a simple implementation would be something like this...


with Test_Package; use Test_Package;

procedure main is 
    Test_Array : aliased Element_Array (1 .. 20);
begin
    -- Initialize the array, then call this function...
    Do_Something_With_Array (In_Array => Test_Array'Access);
end main;


So this does not compile and with countless errors no matter what configuration I try. I have a feeling my approach is fundamentally wrong. Essentially I am trying to pass a constrained array to a package accepting an array of any length, both of the same element type. I would parse the contents of this array using "for in" or 'First -> 'Last or 'Range. 

What is the best way to achieve this goal without using new / free?

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-08-14  8:03 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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