* Gnat3.05 Compile Error Msg
@ 1996-08-20 0:00 Spasmo
1996-08-22 0:00 ` Pascal Ledru
0 siblings, 1 reply; 2+ messages in thread
From: Spasmo @ 1996-08-20 0:00 UTC (permalink / raw)
Hey all.
I'm getting an error message that's baffling me. Here's what I'm
doing and the error:
I'm trying to return an access to a member of a record via a
function. Here's the pertinent code :
type Int_Ptr is access all Integer;
type Rec is
record
A : String(1 .. 10);
B : aliased Integer;
end record;
function Get_Int_Ptr ( R : in Rec ) return Int_Ptr is
begin
return R.B'Access;
end Get_Int_Ptr;
When I tried compiling this under Gnat3.05 for DOS
the line with the return statement was flagged as an
error and I got the following message:
"object has deeper accessibility level than access type"
Now I originally assumed it had something to do with returning
a reference out of the context of a certain scope into the
context of a greater scope which made Ada "think" that there
was the possibility of a dangling reference in the works, but
then I tried turning it into a procedure and passing the
"pointer" to it and performing the assignment and I got the
same error. Does this have something to do with the "pointer"
being embedded in a record? I vaguely remember doing something
similar, but with a non-aggregate (access X in parameter) and
it worked fine so I'm assuming being in a record incurred
extra complications.
In any case is there a way I can do what I want to do (return
an access (for aliasing) to a record field)?
Thanks in advance.
--
Spasmo
"Everyone has secrets, but sometimes you get caught,
So if it's just between us, my silence can be bought"
"Blackmail" by Sloppy Seconds
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Gnat3.05 Compile Error Msg
1996-08-20 0:00 Gnat3.05 Compile Error Msg Spasmo
@ 1996-08-22 0:00 ` Pascal Ledru
0 siblings, 0 replies; 2+ messages in thread
From: Pascal Ledru @ 1996-08-22 0:00 UTC (permalink / raw)
This is a legitimate error message.
Suppose you declare a global variable (I) before your Rec type
(Assume Rec and Get_Int_Ptr are in a declare block), and add the
assignment I := R.B'Access before the return statement; then I
could be used even if you are outside the scopy of R.B'Access.
If you are pretty sure you don't have this accessibility problem,
Unchecked_Access instead of Access should work.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-08-22 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-20 0:00 Gnat3.05 Compile Error Msg Spasmo
1996-08-22 0:00 ` Pascal Ledru
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox