* Help (gnat 3.04)
@ 1996-06-10 0:00 Chong-Kwan Tan
1996-06-11 0:00 ` Chong-Kwan Tan
1996-06-14 0:00 ` Nasser Abbasi
0 siblings, 2 replies; 3+ messages in thread
From: Chong-Kwan Tan @ 1996-06-10 0:00 UTC (permalink / raw)
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 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;
--
cktan@teleport.COM Public Access User --- Not affiliated with Teleport
Public Access UNIX and Internet at (503) 220-1016 (2400-28800, N81)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help (gnat 3.04)
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
1 sibling, 0 replies; 3+ messages in thread
From: Chong-Kwan Tan @ 1996-06-11 0:00 UTC (permalink / raw)
Hi,
I have found the problem. Could have used a more meaning error message
from gnat.
The solution is to change procedure Init(Pool : in out Pool_type)
to procedure Init(Pool: access Pool_type).
-tan
================================================================
In article <ssgafybjgo9.fsf@kelly.teleport.com>
cktan@kelly.teleport.com (Chong-Kwan Tan) writes:
From: cktan@kelly.teleport.com (Chong-Kwan Tan)
Newsgroups: comp.lang.ada
Date: 10 Jun 1996 18:03:18 -0700
Organization: Teleport - Portland's Public Access (503) 220-1016
Path: nntp.teleport.com!usenet
Lines: 49
Sender: cktan@kelly.teleport.com
NNTP-Posting-Host: kelly.teleport.com
X-Newsreader: Gnus v5.0.15
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 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;
--
cktan@teleport.COM Public Access User --- Not affiliated with Teleport
Public Access UNIX and Internet at (503) 220-1016 (2400-28800, N81)
--
cktan@teleport.COM Public Access User --- Not affiliated with Teleport
Public Access UNIX and Internet at (503) 220-1016 (2400-28800, N81)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help (gnat 3.04)
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
1 sibling, 0 replies; 3+ messages in thread
From: Nasser Abbasi @ 1996-06-14 0:00 UTC (permalink / raw)
To: Chong-Kwan Tan
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! ..).
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1996-06-14 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox