AdaPower Logged in as Guest
Ada Tools and Resources

Ada 95 Reference Manual
Ada Source Code Treasury
Bindings and Packages
Ada FAQ


Join >
Articles >
Ada FAQ >
Getting Started >
Home >
Books & Tutorials >
Source Treasury >
Packages for Reuse >
Latest Additions >
Ada Projects >
Press Releases >
Ada Audio / Video >
Home Pages >
Links >
Contact >
About >
Login >
Back
Modifiying the Contents of Limited Types Passed as "in" Parameters (Jean-Pierre Rosen)

The Contents of Limited Types Passed as "in" Parameters
can be modified using the following technique:

with Ada.Text_IO; use Ada.Text_IO;

procedure Rosen_Trick is

   type T;

   type Relay_Type (Reference : access T) is limited null record;

   type T is limited
      record
         Relay : Relay_Type (T'Access);
         Data  : Natural := 0;
      end record;

   function Next (X : in T) return Integer is
      Data : Natural renames X.Relay.Reference.Data;
   begin
      Data := Data+1;
      return Data;
   end Next;

   Test_T : T;

begin

   for N in 1 .. 10 loop
      Put_Line(Integer'Image(Next(Test_T)));
   end loop;

end Rosen_Trick;


(c) 1998-2004 All Rights Reserved David Botton