-- Shows reuse of a stack value by an uninitialized variable
with Text_IO; use Text_IO;
with System.Address_Image;
with Ada.Exceptions; use Ada.Exceptions;
procedure exhheap is
   type Unsigned_32 is mod 2 ** 32;
   --  prev_addr : Unsigned_32;

   count : Natural := 0;

   type bigarray is array (1 .. 10_000) of integer;
   type bap is access bigarray;

   bp : bap := new bigarray;

begin
   put_line("Address of bp: " &
   System.Address_Image(bp.all'address));
   loop
      bp := new bigarray;
      count := count + 1;
   end loop;



exception
      when e: others => 
         new_line;
         put_line (exception_name (e) & ": " & exception_message (e));
         put_line ("Count: " & count'img);
         --  int_address :=
            --  Unsigned_32'Value ("16#" & System.Address_Image(ai'address) & "#");

         put_line("Address of bp: " &
         System.Address_Image(bp.all'address));
               -- & " = " & prev_addr'img);
end exhheap;

--  Address of bp: 0807F008
--  
--  STORAGE_ERROR: heap exhausted
--  Count:  80377
--  Address of bp: BFF57310