From: nasser@apldbio.com (Nasser Abbasi)
To: cktan@kelly.teleport.com (Chong-Kwan Tan)
Subject: Re: Help (gnat 3.04)
Date: 1996/06/14
Date: 1996-06-14T00:00:00+00:00 [thread overview]
Message-ID: <nhvigvyvls.fsf@paralysys> (raw)
In-Reply-To: ssgafybjgo9.fsf@kelly.teleport.com
From: cktan@kelly.teleport.com (Chong-Kwan Tan)
Hi,
I am trying to link all items in an array into a list and gnat 3.04 gives
me this error:
% gnatmake tt.adb
gcc -c tt.adb
tt.adb:21:37: object has deeper accessibility level than access type
gnatmake: "tt.adb" compilation error
Could someone tell me why?
Thanks,
-tan
====================================================================
1 procedure TT is
2
3 type Item_Type;
4 type Item_Ptr_Type is access all Item_Type;
5 type Item_Type is
6 record
7 Next : Item_Ptr_Type;
8 end record;
9 type Item_Table_Type is
10 array (Positive range <>) of aliased Item_Type;
11
12 type Pool_Type is
13 record
14 Item : Item_Table_Type(1..10);
15 end record;
16
17 procedure Init
18 (Pool : in out Pool_Type) is
19 begin
20 for I in 2 .. Pool.Item'Last loop
21 Pool.Item(I-1).Next := Pool.Item(I)'Access;
22 end loop;
23 Pool.Item(Pool.Item'Last).Next := null;
24 end Init;
25
26 P : Pool_Type;
27 begin
28 Init(P);
29 end TT;
--
You are passing P as In OUT, this seems to be the cause of the problem.
the only think I could think of is that at line 21, the right hand
side is an access to the local copy of pool.item(I) that is passed as "IN",
so this copy of the P object sits on the call frame of procedure Init, i.e.
it is a local copy of P that Init is processing, and so, the program is
trying to take the address of a local object and assign it to a object
whose dynamic life is longer (the right hand side), since pool is also
passed in as OUT parameter, which refers to object outside the procedure
Init, and so you get the error.
i.e. Inside Init, when doing pool.item(I)'access, this is getting the address
of the IN copy of P. So, I guess this means one can not pass in an
object as IN OUT if one intends to gets its address ? it is the only
thinh that would explain to me as it seems on the surface the access type
life time rules are obeyed...
Any way, to Init pool , just call Init with pool as OUT only and that
will work, since this way the adress that is being taken belong to an
object that lives as long as what is being assigned to, which is itself,
so Ada is happy, end every one is happy, and life is good.
procedure T is
type Item_Type;
type Item_Ptr_Type is access all Item_Type;
type Item_Type is
record
Next : Item_Ptr_Type;
end record;
type Item_Table_Type is
array (Positive range <>) of aliased Item_Type;
type Pool_Type is
record
Item : Item_Table_Type(1..10);
end record;
P : Pool_Type;
Procedure Init_ver2 (Pool: out Pool_Type) is
begin
for I in 2 .. P.Item'Last loop
P.Item(I-1).Next :=
P.Item(I)'Access;
end loop;
P.Item(P.Item'Last).Next := null;
end Init_ver2;
begin
Init_Ver2(P);
end T;
--
Nasser Abbasi. C/C++/Ada Solaris. GeneAssist - A client/server
application for Nucleic acid and protein sequence search and analysis.
PE-Applied BioSystem division. email: nasser@apldbio.com
MSEE, MSCS, MSCE, FM (and Karpov is my chess hero! ..).
prev parent reply other threads:[~1996-06-14 0:00 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-06-10 0:00 Help (gnat 3.04) Chong-Kwan Tan
1996-06-11 0:00 ` Chong-Kwan Tan
1996-06-14 0:00 ` Nasser Abbasi [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox