home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12436 < prev    next >
Encoding:
Text File  |  1992-08-17  |  3.3 KB  |  92 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!caen!hellgate.utah.edu!fcom.cc.utah.edu!swillden
  3. From: swillden@news.ccutah.edu (Shawn Willden)
  4. Subject: Re: Tagged Pointers
  5. Message-ID: <1992Aug17.174931.1376@fcom.cc.utah.edu>
  6. Sender: news@fcom.cc.utah.edu
  7. Organization: University of Utah Computer Center
  8. X-Newsreader: Tin 1.1 PL3
  9. References: <1992Aug14.234242.8418@ucc.su.OZ.AU>
  10. Date: Mon, 17 Aug 92 17:49:31 GMT
  11. Lines: 79
  12.  
  13. maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  14. : In article <1992Aug13.173401.14944@fcom.cc.utah.edu> swillden@news.ccutah.edu (Shawn Willden) writes:
  15. : >That's what I understood from your previous posts (TU*!=TP) and I was
  16. : >suggesting that maybe there is a good argument for making this so.
  17. : >What are the arguments against it?
  18. : >
  19. :     There's not so much an argument against it as a simple fact
  20. : that th're different. The tagged pointer has the tag in the pointer
  21. : (conceptually at least). It is a pointer that can point to one
  22. : of several types.
  23. :     A tagged union has the tag in the union.  It is an object
  24. : of one of several types.  A pointer to
  25. : a tagged union is an *ordinary* pointer.
  26. :     Tagged pointers are a special case of tagged unions.
  27. : You can of course have a pointer to a tagged pointer, etc.
  28. : You wouldnt want that to be a tagged pointer would you?
  29. : Or perhaps you would?
  30.  
  31. No, I don't think so.  Not if we want to allow:
  32.  
  33.     [T1,T2,T3]** foo = new [T1,T2,T3]*[NUM_ELEMS];
  34.  
  35. (if I understand your syntax).  What I mean is a ordinary pointer 
  36. to an array of tagged pointers.
  37.  
  38. :     It all depends on whether tagged pointers are a genuine
  39. : type or not. If it is, all the above things must be distinct.
  40. : If not (I suggested not in my post) then maybe we can make
  41. : a pointer to a tagged union work as if it were a tagged
  42. : pointer. This would homogenise the interface. More work
  43. : for the compiler, less for the programmmer. Less control
  44. : for the programmer too.
  45.  
  46. Hmmm.  It appears I didn't explain myself very well because that is
  47. precisely what *I* was suggesting.  I suppose the difference lies in
  48. my consideration of TP's and TU's as different types but (as I said)
  49.  
  50.     1)    *TP yields a TU
  51.     2)    &TU yields a TP
  52.  
  53. whereas you suggested that they not be actual *types* but that we 
  54. make them work like the above anyway.  Same effect, different words.
  55. Have I got this right?
  56.  
  57. :     So the issue is whether a tagged pointer is a proper type
  58. : or just a sort of syntactic sugaring that supports a new 
  59. : mechanism for genericity. My thinking was the latter.
  60.  
  61. I think your thinking is better :-)  TP couldn't be a proper type
  62. anyway.  If anything, TP would be a *family* of types.
  63.  
  64. :     Any comments?
  65.  
  66. Getting back to the question that started this exchange (should we have
  67. tagged references?), I think that they're probably unnecessary for the
  68. case I was presenting (by which I mean that they don't greatly simplify 
  69. anything).  If I have a TP and wish to pass a reference to what it points 
  70. to to a function I can just say:
  71.  
  72. void foo([T1,T2,T3]& fred)    // fred is a ref to a TU, not a tagged ref.
  73.     {...}
  74.  
  75. void bar();
  76.     {
  77.     [T1,T2,T3]* barney;
  78.     ...
  79.     foo(*barney);        // *barney is a TU, foo gets a ref to it.
  80.     }
  81.  
  82. at least that is what the programmer may think.  In fact TU and TP are not
  83. types but the syntax of the sugar looks right.  Actually, does it really 
  84. matter whether we call [T1,T2,T3]& a ref to a tagged union or a tagged 
  85. ref?
  86.  
  87. Shawn Willden
  88. swillden@icarus.weber.edu
  89.