* access type problems
@ 1998-11-26 0:00 Ramon Costa Castelló
1998-11-27 0:00 ` Mats Weber
0 siblings, 1 reply; 2+ messages in thread
From: Ramon Costa Castelló @ 1998-11-26 0:00 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 1045 bytes --]
Hi,
If I try to compile this system, composed
by file buffer.ads and main.adb:
buffer.ads:
package buffer is
type Cell is
record
A:Integer;
end record;
type Ptr_Cell is access all Cell;
end buffer;
main.adb :
with buffer; use buffer;
procedure Main is
A: aliased Cell;
B: Ptr_Cell;
begin
B:=A'access;
end Main;
I get the following message (from gnat.3.10p under windows'NT) :
main.adb:9:07: object has deeper accessibility level than access type
Differently if I try to compile the system composed by files
buffer2.ads and main2.adb:
buffer2.ads:
package buffer2 is
type Cell is
record
A:Integer;
end record;
end buffer2;
main2.adb:
with buffer2; use buffer2;
procedure main2 is
type Ptr_Cell is access all Cell;
A: aliased Cell;
B: Ptr_Cell;
begin
B:=A'access;
end main2;
it compiles perfectly without an error or
warning.
Can Anyone explain me the difference between both codes ?
How can I solve the problem appearing in the first one ?
Best Regards,
Ramon Costa-Castello
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Card for Ramon Costa Castell� --]
[-- Type: text/x-vcard; charset=us-ascii; name="costa.vcf", Size: 459 bytes --]
begin:vcard
n:Costa-Castell�;Ramon
tel;fax:+34-93-401-6605
tel;work:+34-93-401-6657
x-mozilla-html:FALSE
url:http://www.ic.upc.es/~costa
org:Institut d'Organitzaci� i Control de Sistemes Industrials (UPC);Enginyeria de Sistemes Autom�tica i Inform�tica Industrial
adr:;;Av. Diagonal 647, 11;Barcelona;CATALUNYA;08028;SPAIN
version:2.1
email;internet:costa@ioc.upc.es
title:Assistant Professor
x-mozilla-cpt:;-1
fn:Costa-Castell�, Ramon
end:vcard
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: access type problems
1998-11-26 0:00 access type problems Ramon Costa Castelló
@ 1998-11-27 0:00 ` Mats Weber
0 siblings, 0 replies; 2+ messages in thread
From: Mats Weber @ 1998-11-27 0:00 UTC (permalink / raw)
Ramon Costa Castell� wrote:
> package buffer is
> type Cell is
> record
> A:Integer;
> end record;
> type Ptr_Cell is access all Cell;
This access type is at the library level (the most global level).
> end buffer;
>
> main.adb :
>
> with buffer; use buffer;
> procedure Main is
The fact that this is a main program is not relevant. Ada rules treat it
just as a normal subprogram.
> A: aliased Cell;
> B: Ptr_Cell;
> begin
> B:=A'access;
As A is in a subprogram, its access level is one deeper than the library
level. The subprogram Main could be called from elsewhere, and thus the
call would return before the program terminates. So A could possibly
cease to exist before the access type Buffer.Ptr_Cell, and access values
are not allowed to outlive the object they point to.
> end Main;
> package buffer2 is
> type Cell is
> record
> A:Integer;
> end record;
> end buffer2;
> with buffer2; use buffer2;
> procedure main2 is
> type Ptr_Cell is access all Cell;
> A: aliased Cell;
> B: Ptr_Cell;
In this case, the accessibility level of the object and that of the
access type are the same, so there is no problem.
> begin
> B:=A'access;
> end main2;
>
> it compiles perfectly without an error or
> warning.
This is normal.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-11-27 0:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-26 0:00 access type problems Ramon Costa Castelló
1998-11-27 0:00 ` Mats Weber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox