[comp.sys.mac.programmer] Update: THINK C 4.0 objects/C++ portability macros

salzman@randvax.UUCP (Isaac Salzman) (10/03/89)

i've made one minor change in class.h: C++ destructors must be
declared virtual in order to have compatible behaviour with
THINK C objects and their use of the Destroy() method in class.h.
included are context diffs to class.h and the README file.

for those who requested a binhex/stuffit copy -- i've sent one off to
info-mac. i originally posted in shar format since i assume most people
reading Usenet are on a UNIX system and, that anyone interested in this
stuff would probably be doing C++ on a UNIX system (though you could be on a
PC -- but WHY??!! :-)

		-Isaac (salzman@rand.org)

------------------------------------------------------------------------

*** README.orig	Tue Oct  3 01:28:44 1989
--- README	Tue Oct  3 01:28:47 1989
***************
*** 7,18 ****
  	as desired so long as this copyright notice remains
  	in tact.
  
! 	$Header: /tmp_mnt/amnt/lh/salzman/src/class/RCS/README,v 1.1 89/09/17 15:01:41 salzman Exp $
  
  	$Log:	README,v $
  	Revision 1.1  89/09/17  15:01:41  salzman
  	Initial revision
! 	
  */
  
  The contents of this archive are as follows:
--- 7,21 ----
  	as desired so long as this copyright notice remains
  	in tact.
  
! 	$Header: /tmp_mnt/amnt/lh/salzman/src/class/RCS/README,v 1.2 89/10/03 00:32:58 salzman Exp Locker: salzman $
  
  	$Log:	README,v $
+ 	Revision 1.2  89/10/03  00:32:58  salzman
+ 	added note about virtual destructors
+ 	
  	Revision 1.1  89/09/17  15:01:41  salzman
  	Initial revision
! 	 
  */
  
  The contents of this archive are as follows:
***************
*** 311,317 ****
       #define DestroyObject(Object) { Object->Destroy();delete(Object); }
       #define DESTROY_SUPER inherited::Destroy()
  	 
! C++: #define DECL_DEST(Class) ~Class
       #define DEF_DEST(Class) Class::~Class
       #define DestroyObject(Object) delete Object
       #define DESTROY_SUPER
--- 314,320 ----
       #define DestroyObject(Object) { Object->Destroy();delete(Object); }
       #define DESTROY_SUPER inherited::Destroy()
  	 
! C++: #define DECL_DEST(Class) virtual ~Class
       #define DEF_DEST(Class) Class::~Class
       #define DestroyObject(Object) delete Object
       #define DESTROY_SUPER
***************
*** 346,356 ****
       I chose to stick with this convention. If you want to append the 
       class name in TCO, no problem: just use Destroy##Class, but then
       you'd have to pass the class name as an argument as well....
!      
!      C++ automatically calls destructors up the inheritance hierarchy,
!      TCO doesn't (it's just another method in TCO), therefore you need
!      to use DESTROY_SUPER in TCO -- which just calls the super classes
!      Destroy() method, and does nothing in C++.
  
  ------------------------------------------------------------------------
  
--- 349,374 ----
       I chose to stick with this convention. If you want to append the 
       class name in TCO, no problem: just use Destroy##Class, but then
       you'd have to pass the class name as an argument as well....
! 
! 
!      C++ automatically calls virtual destructors up the inheritance 
!      hierarchy. TCO doesn't (it's just another method in TCO), 
!      therefore you need to use DESTROY_SUPER in TCO -- which just 
!      calls the super classes  Destroy() method, and does nothing in C++.
! 
!      NOTE: destructors MUST be declared virtual in C++ in order for
!      them to have compatible behaviour with TCO. There are some
!      obscure instances where complete compatability is impossible.
!      If you call a virtual destructor for a derived class, it will
!      work its way up the hierarchy calling destructors for each
!      base class. As it leaves a destructor, the object does not belong
!      to that class anymore. It changes its identity along the way. The
!      result is that if you're calling virtual methods in your destructors,
!      you will not get the expected results. Since, in TCO, the Destroy 
!      method is like any other method, it does not have this odd side 
!      effect. It turns out that Cfront 1.2 is broken in this respect
!      whereas GNU C++ does the right thing (I found this out while
!      reporting what I thought may have been a bug in g++).
  
  ------------------------------------------------------------------------
  
*** class.h.orig	Tue Oct  3 01:27:56 1989
--- class.h	Tue Oct  3 00:34:21 1989
***************
*** 12,20 ****
  
  /*
   *------------------------------------------------------------------
!  * $Header: /tmp_mnt/amnt/lh/salzman/src/class/RCS/class.h,v 1.1 89/09/17 15:01:38 salzman Exp $
   *------------------------------------------------------------------
   * $Log:	class.h,v $
   * Revision 1.1  89/09/17  15:01:38  salzman
   * Initial revision
   * 
--- 12,24 ----
  
  /*
   *------------------------------------------------------------------
!  * $Header: /tmp_mnt/amnt/lh/salzman/src/class/RCS/class.h,v 1.2 89/10/03 00:33:15 salzman Exp Locker: salzman $
   *------------------------------------------------------------------
   * $Log:	class.h,v $
+  * Revision 1.2  89/10/03  00:33:15  salzman
+  * all C++ destructors are virtual for compatability with TCO
+  * (see README)
+  * 
   * Revision 1.1  89/09/17  15:01:38  salzman
   * Initial revision
   * 
***************
*** 74,80 ****
  # define RETURN_THIS
  
    /* things needed for destroying objects */
! # define DECL_DEST(Class) ~Class
  # define DEF_DEST(Class) Class::~Class
  # define DestroyObject(Object) delete Object
  # define DESTROY_SUPER
--- 78,84 ----
  # define RETURN_THIS
  
    /* things needed for destroying objects */
! # define DECL_DEST(Class) virtual ~Class
  # define DEF_DEST(Class) Class::~Class
  # define DestroyObject(Object) delete Object
  # define DESTROY_SUPER