-- Print some memory addresses!
with Unchecked_Conversion;
with Unchecked_Deallocation;
with Text_IO; use Text_IO;
procedure printmem is
type IntPointer is access Integer;
-- A modular type for 32 bit addresses!
type AddressType is mod 2**32;
-- A I/O package for addresses
package Address_IO is new Text_IO.Modular_IO (Num => AddressType);
use Address_IO;
-- Output a string, an address, and a newline
procedure put_line(s: String; a: AddressType) is begin put_line(s & a'img); end put_line;
-- Convert from an IntPointer to an AddressType
function Convert is new Unchecked_Conversion (
Source => IntPointer,
Target => AddressType);
procedure Dispose is new Unchecked_Deallocation (
Object => Integer,
Name => IntPointer);
a: AddressType;
p, q, r: IntPointer;
begin
p := new Integer'(33);
a := convert(p);
put_line("address in p: ", a);
q := new Integer'(44);
put_line("address in q: ", convert(q));
q := new Integer'(55);
put_line("address in q: ", convert(q));
q := new Integer'(55);
put_line("address in q: ", convert(q));
dispose(p);
put_line("address in p: ", convert(p)); -- P should be 0 (ie null)
r := new Integer'(55);
put_line("address in r: ", convert(r));
end printmem;
-- address in p: 134539296
-- address in q: 134539312
-- address in q: 134539328
-- address in q: 134539344
-- address in p: 0
-- address in r: 134539296