comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: ADA Objects Help!
Date: 24 Jan 1995 22:18:39 GMT
Date: 1995-01-24T22:18:39+00:00	[thread overview]
Message-ID: <3g3uc0$hm6@watnews1.watson.ibm.com> (raw)
In-Reply-To: 3fu6qc$pc5@gnat.cs.nyu.edu

In C++, members may be static or nonstatic and may be data members or
function members: 

   class C {
      public: 
         int nonstatic_data_member;
         static int static_data_member;
         void nonstatic_function_member(int x);
         static void static_function_member(int x);
   };

   static void C::nonstatic_function_member(int x) {
      [references to static_data_member or nonstatic_data_member]
   }

   static void C::static_function_member(int x) {
      [references to static_data_member, but not nonstatic_data_member]
   }

These reflect the unified/confused role of a class as a type definition
and as a module.  The equivalent in Ada is: 

   package C_Module is

      type C_Type is
         record
            Nonstatic_Data_Member: Integer;
         end record;

      Static_Data_Member: Integer;

      procedure Nonstatic_Function_Member
         (This: access C_Type; X: in Integer);

      procedure Static_Function_Member (X: in Integer);

   end C_Module;

   package body C_Module is

      procedure Nonstatic_Function_Member
         (This: access C_Type; X: in Integer) is
         ...
      begin
         [references to Static_Data_Member or This.Nonstatic_Data_Member]
      end Nonstatic_Function_Member;

      procedure Static_Function_Member (X: in Integer) is
         ...
      begin
         [references to Static_Data_Member]
      end Static_Function_Member;

   end C_Module;

The Ada formulation is actually a more accurate depiction of the usual
C++ implementation than is the C++ formulation.  The C++ formulation
suggests that each object of class C has space set aside for its own copy
of the function, or at least of a pointer to the function.  (This effect
can be achieved in Ada with a record component belonging to an
access-to-subprogram type.)  In reality, since the function is not
virtual, the function body is the same for all members of the class, so
there is only one copy of it and it is called directly, without going
through any pointers.  A pointer to the object "containing" the called
function is passed to this single copy through the implicit parameter
"this", and a reference to nonstatic_function_member in the function body
is just a shorthand for this->nonstatic_function_member.

--
Norman H. Cohen    ncohen@watson.ibm.com



  reply	other threads:[~1995-01-24 22:18 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3f9g1u$j4m@nps.navy.mil>
     [not found] ` <D2H5un.FEr@nntpa.cb.att.com>
     [not found]   ` <3fcs59$70s@nps.navy.mil>
     [not found]     ` <3ff186$c19@gnat.cs.nyu.edu>
1995-01-17 17:57       ` ADA Objects Help! Mats Weber
1995-01-18 17:47         ` Robert Dewar
1995-01-20 16:04           ` Mats Weber
1995-01-21 18:59             ` Robert Dewar
1995-01-23 12:03               ` Robb Nebbe
1995-01-25 20:44                 ` Mats Weber
1995-01-25 20:44               ` Mats Weber
1995-01-27  4:03                 ` Robert Dewar
1995-01-26  3:36           ` swdecato
     [not found]         ` <3fhggr$11dp@watnews1.watson.ibm.com>
     [not found]           ` <Mats.Weber-1901951739360001@mlma11.matrix.ch>
1995-01-20 17:22             ` Norman H. Cohen
1995-01-23 16:37               ` Mats Weber
1995-01-25 20:44               ` Mats Weber
1995-01-27  4:05                 ` Robert Dewar
1995-01-19 11:57   ` Robert M. Wilkinson
1995-01-22 18:06     ` Robert Dewar
1995-01-24 22:18       ` Norman H. Cohen [this message]
1995-01-25  1:26         ` swdecato
1995-01-25 18:18           ` Bob Kitzberger
1995-01-25 20:11             ` Bob Kitzberger
1995-01-26 15:31           ` Norman H. Cohen
     [not found]           ` <D330pK.M1@nntpa.cb.att.com>
1995-01-28 21:46             ` John DiCamillo
1995-01-30 14:13               ` David Emery
1995-01-30 22:50               ` Subject/Object Confusion Syndrome [was: Ada Objects Help] John Volan
1995-02-01 14:33                 ` Norman H. Cohen
     [not found]                   ` <D3DpJu.4nK@swlvx2.msd.ray.com>
     [not found]                     ` <D3H7J3.B2x@inmet.camb.inmet.com>
1995-02-06 10:32                       ` Robb Nebbe
     [not found]                     ` <3gu21g$ch@portal.gmu.edu>
1995-02-06 14:01                       ` John Volan
1995-02-01 22:37                 ` Maarten Landzaat
     [not found]                   ` <3h1ahp$gf5@gnat.cs.nyu.edu>
     [not found]                     ` <3h3jmp$1h1@Starbase.NeoSoft.COM>
1995-02-07 14:39                       ` John Volan
1995-02-09  2:25                         ` David Weller
1995-01-29 18:19             ` ADA Objects Help! mat
     [not found]               ` <1995Feb5.180601@hobbit>
1995-02-07 23:04                 ` Subject/Object Confusion Syndrome [was: Ada Objects Help] John Volan
1995-01-25  9:48       ` ADA Objects Help! mat
1995-01-23 10:01     ` calling syntax (was Re: Ada Objects) Robb Nebbe
1995-01-23 18:08       ` John DiCamillo
1995-01-23 23:47     ` ADA Objects Help! Ed Osinski
1995-01-25  6:19       ` David O'Brien
     [not found] ` <1995Jan16.132400@lglsun.epfl.ch>
     [not found]   ` <131279@cup.portal.com>
1995-01-20 16:52     ` Ada " Robert Dewar
1995-01-22 18:30       ` Tucker Taft
1995-01-24 22:09         ` Jacob Sparre Andersen
1995-01-26 16:20           ` Robert A Duff
1995-01-27 17:04             ` Robert A Duff
1995-01-27 19:58             ` Tucker Taft
1995-01-20 17:41   ` Mark S. Hathaway
1995-01-23 10:41     ` Robb Nebbe
1995-01-23 11:53     ` Stephane Barbey
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox