comp.lang.ada
 help / color / mirror / Atom feed
From: WishList@2600.com (Technobabble)
Subject: Thanks Tucker, It works !!!
Date: 1998/09/19
Date: 1998-09-19T00:00:00+00:00	[thread overview]
Message-ID: <WishList-1909981556420001@a2.phoenix-9.goodnet.com> (raw)

Greetings,

The final code, which I compiled with GNAT, outputs the following:

test_pkg
test_pkg
test_pkg
test_pkg
test_pkg

Basically, I wanted to specify an unconstrained array in a spec for a user
and then let the user constrain it.  Then a procedure, also in the spec,
could determine the size of the array, in this case 5, since the loop
executed 5 times. But I had to do it with an access type per design
requirements.

Below is the final code, I still don't really understand the aliased, all,
and access keywords working together to allow this sort of C-like pointer
operation, but Ada95 does allow it.  Anyone care to explain, I'd love to
learn the reasons behind allowing pointer operations.

Question:  would this work in Ada83 not having these keywords???


Here is the final code:



****
file test_pkg.ads
****
package test_pkg is

 type xyz_array is array (integer range <>) of integer;   -- this is it

 type xyz_array_pointer is access all xyz_array;

 type xyz_array_pointer_array is array (1..100) of xyz_array_pointer;


 type Object is
     record
        XYZ : xyz_array_pointer_array;    
        abc : integer;
     end record;

 -- user can define this array externally, just here for demo
 xyz5_array : aliased xyz_array := (1..5 => 0);

 procedure my_range (This : in out Object); 

end test_pkg;



****
file: my_main.adb
****
with test_pkg; use test_pkg;
procedure my_main is
   my_this : Object;
begin
   my_range (my_this);
end my_main;



****
file: test_pkg.adb
****

with Text_IO; use Text_IO;
package body test_pkg is

procedure my_range (This : in out Object) is
begin 
        -- next line can be externally done by user, here for demo
        This.XYZ(1) := xyz5_array'ACCESS;  -- address of xyz5_array is assigned
        for I in This.XYZ(1)'RANGE
        loop
          put_line ("test_pkg");
        end loop;

end my_range;

end test_pkg;




             reply	other threads:[~1998-09-19  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-09-19  0:00 Technobabble [this message]
1998-09-20  0:00 ` Thanks Tucker, It works !!! dewarr
1998-09-20  0:00   ` Technobabble
  -- strict thread matches above, loose matches on Subject: below --
1998-09-20  0:00 tmoran
replies disabled

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