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

  1. Xref: sparky comp.lang.c++:11677 comp.std.c++:976
  2. Newsgroups: comp.lang.c++,comp.std.c++
  3. Path: sparky!uunet!world!wmm
  4. From: wmm@world.std.com (William M Miller)
  5. Subject: Re: Language extensions for run-time type identification
  6. Message-ID: <BryFLI.Hz2@world.std.com>
  7. Organization: Software Emancipation Technology, Inc.
  8. References: <1992Jul23.183041.147@uunet.uu.net!mole-end> <1992Jul24.141611.19647@cadsun.corp.mot.com>
  9. Date: Sat, 25 Jul 1992 17:08:05 GMT
  10. Lines: 38
  11.  
  12. I'd like to make a short comment about the rationale for providing
  13. RTTI only for classes with virtual functions -- even though I
  14. suggested what I considered to be a practical way of providing RTTI
  15. for classes without virtual functions (not tagged pointers, BTW), I
  16. can understand the reasoning for restricting RTTI.  It's not just
  17. convenience in piggybacking onto existing technology, although that is
  18. an attractive aspect of the current proposal.  The real question is
  19. when RTTI is likely to be used.
  20.  
  21. Consider this: dynamic typing is only required when you've "lost" the
  22. exact type of the object to which an expression refers.  In all other
  23. cases, the static type of the expression is sufficient, and the
  24. compiler can just provide a direct reference to the typeinfo if the
  25. program requests type information.
  26.  
  27. There are only two ways to "lose" the exact type in C++ (apart from
  28. explicit casting to an unrelated type, for instance): conversion of a
  29. pointer/reference to a derived class into a pointer/reference to a
  30. base class, and conversion to void*.  Doing something about the latter
  31. is either very expensive or requires breaking compatibility with C
  32. void* pointers (tagged pointers), so realistically we are talking
  33. about a requirement for RTTI that *only* has to deal with the results
  34. of derived-to-base conversions.
  35.  
  36. The question, then, is under what circumstances do such conversions
  37. occur?  The premise of the current proposal is that you don't *do*
  38. such conversions unless you have provided for polymorphic behavior,
  39. i.e., virtual functions.  Inheritance for factoring and sharing of
  40. representation and code is fine, but in such applications you
  41. typically don't rely on derived-to-base conversions.
  42.  
  43. The challenge, then, for those who view RTTI-via-vtable as
  44. insufficient is to provide *concrete* counterexamples to this
  45. assumption: applications where derived-to-base casting does occur
  46. without the need for virtual functions and for which RTTI would
  47. nevertheless be useful.  Are there such applications?
  48.  
  49. -- William M. Miller, wmm@world.std.com
  50.