From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,c890e6ab3fb2c5fc X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,c890e6ab3fb2c5fc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1995-01-24 14:51:14 PST Path: pad-thai.cam.ov.com!bloom-beacon.mit.edu!gatech!howland.reston.ans.net!pipex!uunet!newsgate.watson.ibm.com!watnews.watson.ibm.com!ncohen From: ncohen@watson.ibm.com (Norman H. Cohen) Newsgroups: comp.lang.ada,comp.lang.c++ Subject: Re: ADA Objects Help! Date: 24 Jan 1995 22:18:39 GMT Organization: IBM T.J. Watson Research Center Distribution: world Message-ID: <3g3uc0$hm6@watnews1.watson.ibm.com> References: <3f9g1u$j4m@nps.navy.mil> <3flk3r$8qj@gdls.com> <3fu6qc$pc5@gnat.cs.nyu.edu> Reply-To: ncohen@watson.ibm.com NNTP-Posting-Host: rios8.watson.ibm.com Xref: pad-thai.cam.ov.com comp.lang.ada:14632 comp.lang.c++:70756 Date: 1995-01-24T22:18:39+00:00 List-Id: 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