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

  1.                                        -- Chapter 13 - Program 3
  2. with Text_IO, Unchecked_Deallocation;
  3. use Text_IO;
  4.  
  5. procedure Access3 is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    type MY_RECORD is
  11.       record
  12.          Age     : INTEGER;
  13.          Initial : CHARACTER;
  14.          Sex     : CHARACTER;
  15.       end record;
  16.  
  17.    type ACCESS_MY_DATA is access MY_RECORD;
  18.  
  19.    procedure Free is new
  20.                 Unchecked_Deallocation(MY_RECORD,ACCESS_MY_DATA);
  21.  
  22.    Myself  : ACCESS_MY_DATA;
  23.    Friend  : ACCESS_MY_DATA := new MY_RECORD'(30,'R','F');
  24.  
  25.    Result : BOOLEAN;
  26.  
  27. begin
  28.  
  29.    Myself := new MY_RECORD;
  30.  
  31.    Myself.Age := 34;
  32.    Myself.Initial := 'D';
  33.    Myself.Sex := 'M';
  34.  
  35.    Friend := new MY_RECORD'(31,'R','F');
  36.  
  37.    Put("My age is");
  38.    Put(Myself.Age,3);
  39.    Put(" and my initial is ");
  40.    Put(Myself.Initial);
  41.    New_Line;
  42.  
  43.    Friend.all := Myself.all;
  44.  
  45.    Result := Friend.all = Myself.all;    -- TRUE because of line 43
  46.    Result := Friend = Myself;            -- FALSE because they point
  47.                                          -- to different things.
  48.  
  49.    Free(Myself);
  50.    Free(Friend);
  51.  
  52. end Access3;
  53.  
  54.  
  55.  
  56.  
  57. -- Result of execution
  58.  
  59. -- My age is 34 and my initial is D
  60.  
  61.