home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / answers / ch13_2a.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.2 KB  |  58 lines

  1.                           -- Chapter 13 - Programming Exercise 2
  2.                                        -- Chapter 13 - Program 1
  3. with Text_IO, Unchecked_Deallocation;
  4. use Text_IO;
  5.  
  6. procedure Ch13_2a is
  7.  
  8.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  9.    use Int_IO;
  10.  
  11.    type POINT_SOMEWHERE is access INTEGER;
  12.    Index,Arrow,There : POINT_SOMEWHERE;
  13.  
  14.    procedure Free is new
  15.                 Unchecked_Deallocation(INTEGER, POINT_SOMEWHERE);
  16.  
  17. begin
  18.    Index := new INTEGER;
  19.    Index.all := 13;
  20.    Put("The value is");
  21.    Put(Index.all);
  22.    New_Line;
  23.  
  24.    Arrow := new INTEGER;
  25.    Arrow.all := Index.all + 16;
  26.    There := Arrow;
  27.    Put("The values are now");
  28.    Put(Index.all);
  29.    Put(Arrow.all);
  30.    Put(There.all);
  31.    New_Line;
  32.  
  33.    There.all := 21;
  34.    Put("The values are now");
  35.    Put(Index.all);
  36.    Put(Arrow.all);
  37.    Put(There.all);
  38.    New_Line;
  39.  
  40.    Free(Index);
  41.    Free(Arrow);
  42.  
  43. end Ch13_2a;
  44.  
  45.  
  46.  
  47.  
  48. -- Result of execution
  49.  
  50. -- The value is    13
  51. -- The values are now    13    29    29
  52. -- The values are now    13    21    21
  53.  
  54. -- Note that the Free procedure in line 41 could have been done
  55. --   with the access variable There since it is also accessing
  56. --   that data.  Both could not be used however.
  57.  
  58.