-- A simple example showing more of  pointer to a record type
with ada.text_io; use ada.text_io; 
with ada.integer_text_io; use ada.integer_text_io; 
 
procedure boxptrexample2  is 

    type Box is record
        l, w: Integer := 0;
    end record;

    -- A type for pointers to boxes
    type BoxPtr is access Box;

    -- Print the box that is passed as a parameter
    procedure put_line(aBox: Box) is
    begin
        put(aBox.l);
        put(aBox.w);
        new_line;
    end put_line;

    -- Print the box that is pointed to by the parameter
    procedure put_line(aBoxPtr: BoxPtr) is
    begin
        put(aBoxPtr.all.l);
        put(aBoxPtr.all.w);
        new_line;
    end put_line;

    b1: Box;
    p1: BoxPtr;

begin
    -- Allocate and initialize at the same time
    p1 := new Box'(33, 44);

    -- Which put_line does each of these call?
    put_line(p1.all);
    put_line(p1);

    -- Strong typing
    b1 := p1.all;
    -- b1 := p1;     -- Type error
    -- p1 := b1;     -- Type error

    -- Shorthand notation:
    p1.all.l := 55;
    p1.w := 66;

end boxptrexample2;