home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11839 < prev    next >
Encoding:
Text File  |  1992-07-30  |  2.2 KB  |  64 lines

  1. Xref: sparky comp.lang.c++:11839 comp.std.c++:1002
  2. Newsgroups: comp.lang.c++,comp.std.c++
  3. Path: sparky!uunet!sun-barr!cs.utexas.edu!convex!constellation!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  4. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  5. Subject: Re: Language extensions for run-time type identification
  6. Message-ID: <1992Jul30.163821.17353@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: <1992Jul26.014223.6153@uunet.uu.net!mole-end> <1992Jul27.173614.8320@cadsun.corp.mot.com> <1992Jul28.094428.15393@uunet.uu.net!mole-end>
  11. Date: Thu, 30 Jul 1992 16:38:21 GMT
  12. Lines: 50
  13.  
  14. In article <1992Jul28.094428.15393@uunet.uu.net!mole-end> mat@uunet.uu.net!mole-end writes:
  15. >
  16. >> >     Only derivation can make use of RTTI.
  17. >
  18. >> I disagree. Derivation needs RTTI does not mean that only derivation needs  
  19. >> RTTI. Parameterization needs RTTI too (of cause, it is not the C++ template).
  20. >
  21. >RTTI is only needed when an object can have an apparent type and an actual
  22. >type.  In C++, that requires derivation.  
  23.  
  24.     Not so. RTTI could easily be useful for distinguishing between
  25. unrelated types.
  26.  
  27.     In fact, these type *might* have a base in common, but the
  28. is not relevant.
  29.  
  30.     Consider the syntax
  31.  
  32.     f(X[Y,Z]*);
  33.  
  34. which is taken to mean a pointer to X, with downcasting to Y and Z
  35. allowed. If we allow,
  36.  
  37.     f([Y,Z]*);
  38.  
  39. then it is much the same, except that there is no 'default' type,
  40. and the argument cannot be used directly.
  41.  
  42. One can easily see how this can be used to implement a Lisp system:
  43.  
  44.     typdef [float,int,string] atom;
  45.  
  46.     class node {
  47.         node *CAR;
  48.         [node, atom]* CDR;
  49.     };
  50.  
  51. The notion is equivalent to a pascal variant record with run-time
  52. checking on the discriminant.
  53.  
  54. In the case above, tagged pointers may have to be used.
  55.  
  56. When there is a common base with a virtual member, RTTI in the object
  57. can be used instead. But that is an compiler implementation detail.
  58.  
  59. -- 
  60. ;----------------------------------------------------------------------
  61.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  62.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  63. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  64.