-- Shows addresses of local variables decreasing
-- Shows addresses of heap elements increasing
-- Shows reuse of heap variable
with Text_IO; use Text_IO;
with System.Address_Image;
with unchecked_deallocation;
procedure aliasedLocala is
type IntPointer is access Integer;
procedure dispose is new unchecked_deallocation(integer, name=>IntPointer );
p: IntPointer; -- Address of p: BFE4B620
-- Local variables
i: Integer; -- Address of i: BFE4B61C
j: Integer; -- Address of j: BFE4B618
k: Integer; -- Address of k: BFE4B614
-- Output:
-- Address of p.all: 08081008
-- Address of p.all: 08081018
-- Address of p.all: 08081018
begin
put_line("Address of p: " & System.Address_Image(p'address));
put_line("Address of i: " & System.Address_Image(i'address));
put_line("Address of j: " & System.Address_Image(j'address));
put_line("Address of k: " & System.Address_Image(k'address));
p := new Integer;
put_line("Address of p.all: " & System.Address_Image(p.all'address));
p := new Integer;
put_line("Address of p.all: " & System.Address_Image(p.all'address));
dispose(p);
p := new Integer;
put_line("Address of p.all: " & System.Address_Image(p.all'address));
end aliasedLocala;