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

  1. Xref: sparky comp.lang.c++:11841 comp.std.c++:1003
  2. Path: sparky!uunet!dtix!darwin.sura.net!convex!constellation!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Newsgroups: comp.lang.c++,comp.std.c++
  5. Subject: Re: run-time type checking (was: Re: Covariant Types in Derived Classes)
  6. Message-ID: <1992Jul30.171127.18238@ucc.su.OZ.AU>
  7. Date: 30 Jul 92 17:11:27 GMT
  8. References: <1992Jul28.214528.6360@ucc.su.OZ.AU> <1992Jul29.160546.21766@cadsun.corp.mot.com>
  9. Sender: news@ucc.su.OZ.AU
  10. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  11. Lines: 86
  12. Nntp-Posting-Host: extro.ucc.su.oz.au
  13.  
  14. In article <1992Jul29.160546.21766@cadsun.corp.mot.com> shang@corp.mot.com writes:
  15. >In article <1992Jul28.214528.6360@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John  
  16. >MAX Skaller) writes:
  17. >> In article <1992Jul27.170255.8185@cadsun.corp.mot.com> shang@corp.mot.com  
  18. >> 
  19. >>     The proposed RTTI downcast is WORSE: it return a NULL POINTER
  20. >> if the cast fails due to type mismatch on pointers.
  21. >>
  22. >No. The RTTI I suggested does not return any NULL pointers. Quite simple and  
  23. >safe, the compiler does not let you program pass if there is a potential type  
  24. >error. It seems that you did not read what I wrote carefully.
  25.  
  26.     I apologise, I was indeed refering to my understanding of the
  27. current deliberations of the ANSI/ISO committee.
  28.  
  29.     I do not recall how you proposed to constrain downcasting
  30. so it might be detected at compile time (given the function body
  31. to whom the parameter is passed is separately compiled).
  32.  
  33.     Such a constraint must be implemented by modifying the syntax
  34. for parameter declarations, perhaps like so:
  35.  
  36.     f(Base[Derived1,Derived2]*);
  37.  
  38. The pointer of type Base* must be passed EVEN if it does not point
  39. to Derived1 or Derived2, since f may sensibly use the common
  40. base class Base to access the object.
  41.  
  42. This mechanism, incidently, leads to consideration of
  43.  
  44.     f([AnyType1,AnyType2]*);
  45.  
  46. where the types need not be related at all. 
  47.  
  48. >> the proposed RTTI/downcast is any different. It may have slightly
  49. >> better optimistaion oportunities, like all built in features.
  50. >>
  51. >Not just slightly. The compiler can know the specific type in many cases and  
  52. >hence can detect the type error at compile time. 
  53.  
  54.     Could you give another example of how the compiler can detect
  55. incorrect types? Certainly in the case of classes derived from a base
  56. I do not see how passing a base could ever be wrong. And the compiler
  57. *already* detects if a class not derived from the base is passed.
  58.  
  59. >For those types unknown to the  
  60. >compiler, the compiler can also detect the type error through RTTI.  
  61. >> 
  62. >> >Type safe downcast with RTTI will not have the above problems:
  63. >> >
  64. >>     WRONG. You get a system crash if you dont check for 0 pointer.
  65. >>
  66. >Angain, RTTI has nothing to do with null pointer. To return a null pointer for  
  67. >an RTT error is an irresponsible manner. 
  68.  
  69.     Well I am sorry but I was refering to my understanding of the
  70. current state of Bjarnes proposal, in which pointer casts to the
  71. derived type of the wrong type yield a null pointer. (For references,
  72. and exception is raised).
  73.  
  74. >At least, an exception should be  
  75. >raised for the error. I'm even not satisfied with the exception handling  
  76. >because you leave type error at run time! What I suggested is to detect all the  
  77. >type errors at compile time just by explicit run time type check. Sounds  
  78. >strange? I've mentioned this several times in my previous posters and examples  
  79. >are also given and I'm tired of repeating.
  80.  
  81.     I'm sorry but that sound contradictory. The compiler can
  82. ensure a type check is done at run-time, but not statically check
  83. the type at compile time, at least in some cases.
  84. >
  85. >David Shang
  86. >
  87. > -- 
  88. >> ;----------------------------------------------------------------------
  89. >>         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  90. >>     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  91. >> ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  92.  
  93.  
  94. -- 
  95. ;----------------------------------------------------------------------
  96.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  97.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  98. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  99.