home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11706 < prev    next >
Encoding:
Internet Message Format  |  1992-07-28  |  3.7 KB

  1. Xref: sparky comp.lang.c++:11706 comp.std.c++:983
  2. Newsgroups: comp.lang.c++,comp.std.c++
  3. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  4. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  5. Subject: Re: run-time type checking (was: Re: Covariant Types in Derived Classes)
  6. Message-ID: <1992Jul28.214528.6360@ucc.su.OZ.AU>
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  10. References: <1992Jul24.192207.15267@ucc.su.OZ.AU> <1992Jul27.170255.8185@cadsun.corp.mot.com>
  11. Date: Tue, 28 Jul 1992 21:45:28 GMT
  12. Lines: 69
  13.  
  14. In article <1992Jul27.170255.8185@cadsun.corp.mot.com> shang@corp.mot.com writes:
  15. >> In article <1992Jul24.143359.3602@advtech.uswest.com> glw@io.uswest.com  
  16. >(Glenn Williams) writes:
  17. >> >
  18. >> >Ok, let's have an example of a properly designed system. 
  19. >
  20. >In article <1992Jul24.192207.15267@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU  
  21. >(John MAX Skaller) replies:
  22. >> 
  23. >>     But that wont PROVE anything. You have to give me
  24. >> an example of a system that uses downcasting and then I'll
  25. >> show how to write it without downcasting.
  26. >> 
  27. >Your example "mate" is already a good example! And you did not provide a good  
  28. >solution without downcasting. Using virtual function "Species()" can certainly  
  29. >eliminates the necessity of downcast, but it introduces severe problems that a  
  30. >safe downcast would never have.
  31. >
  32. >First of all, you must remember to override the virtual function in each  
  33. >derived class, and give the proper return value. If a forget to override, or if  
  34. >a give a name that happened to be the same name already exists, you make a  
  35. >trouble. The compiler has no way to help you to establish a proper name  
  36. >distribution.
  37.  
  38.     The first is WRONG. Havent you ever head of PURE VIRTUAL FUNCTIONS????
  39.  
  40.     The second is a CONSEQUENCE of being able to 
  41.     chose the species name for each class. Thats
  42.     DESIRABLE if you want to support multiple
  43.     implementation of the same class.
  44.  
  45. >
  46. >Secondly, you must remember to run time check the character strings returned by  
  47. >the virtual function. If you forget, you may put a cat and a rat together! The  
  48. >compiler has no way to help you essure the correct match!
  49.  
  50.     The proposed RTTI downcast is WORSE: it return a NULL POINTER
  51. if the cast fails due to type mismatch on pointers.
  52.  
  53. >
  54. >Lastly, you leave much checking work that should be done at compile time to be  
  55. >done at run time. 
  56.  
  57.     In this case maybe thats true. I dont see how
  58. the proposed RTTI/downcast is any different. It may have slightly
  59. better optimistaion oportunities, like all built in features.
  60.  
  61.  
  62. >On one head, you let down the run time performance. On the  
  63. >other head, you leave errors that should be detected at compile time to the run  
  64. >time.
  65. >
  66. >Type safe downcast with RTTI will not have the above problems:
  67. >
  68. >Firstly, the compiler will generate a proper type identifier for each type. The  
  69. >detailed type information can be stored in files generated by the compiler, and  
  70. >the library can provide a set of suitable functions to access these detail type  
  71. >information through the type id. Howerver, for the purpose of downcast, only  
  72. >the simple type id is needed. The programmer is never bothered by overriding a  
  73. >virtual function that returns a character string or an interger that serves as  
  74. >the type id. No error will be concerned about a mis-produced type id at run  
  75. >time.
  76.  
  77.     WRONG. You get a system crash if you dont check for 0 pointer.
  78. -- 
  79. ;----------------------------------------------------------------------
  80.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  81.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  82. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  83.