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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
  3. From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
  4. Subject: Re: Tagged Pointers
  5. Message-ID: <1992Aug13.082618.18274@ucc.su.OZ.AU>
  6. Sender: news@ucc.su.OZ.AU
  7. Nntp-Posting-Host: extro.ucc.su.oz.au
  8. Organization: MAXTAL P/L C/- University Computing Centre, Sydney
  9. References: <1992Aug9.201515.7353@ucc.su.OZ.AU> <1992Aug10.221849.19455@fcom.cc.utah.edu>
  10. Date: Thu, 13 Aug 1992 08:26:18 GMT
  11. Lines: 88
  12.  
  13. In article <1992Aug10.221849.19455@fcom.cc.utah.edu> swillden@news.ccutah.edu (Shawn Willden) writes:
  14. >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  15. >: In article <memo.565692@cix.compulink.co.uk> vadim@cix.compulink.co.uk writes:
  16. >: >[ deleted text]
  17. >: >
  18. >: >Ok, what about tagged references for ortogonality?
  19. >: 
  20. >:     And tagged values, right?  (Also known as tagged unions).
  21. >: 
  22. >:     I originally put 'and you have tagged references just like
  23. >: tagged pointers (so I needn't describe them) execpt that the
  24. >: syntax is different' in my post.
  25. >: 
  26. >:     But now I don't think that you can HAVE tagged references.
  27. >: Tagged pointers are VARIABLES, like pointers. References are not,
  28. >: they cannot be changed. If you had tagged references you would not 
  29. >: be able to use them where you could use a pointer:
  30. >: 
  31. >:     [T1, T2]& r;
  32. >:     r.function();
  33. >: 
  34. >: Am I wrong on this, do tagged references make sense?
  35. >
  36. >Sure they make sense.  Are they necessary?  (Assuming tagged pointers
  37. >are).  Look at the following.
  38.  
  39.     They're never *necessary*. But useful? and sound? and safe?
  40.  
  41. >
  42. >    void foo(const [T1, T2, T3]& r)  // This idiom pops up now and then ;->
  43. >    { // do something with r }
  44. >
  45. >    void bar()
  46. >    {
  47. >    [T1, T2, T3]* r;
  48. >    T1 t1;
  49. >
  50. >    r= &t1;
  51. >    foo(*r);
  52. >    }
  53. >
  54. >I can see three ways to make this work:
  55. >    1)    Make foo a template function (void foo(T& r)).  If I
  56. >        understood your proposal, dereferencing r would create
  57. >        something like:
  58. >            switch (r.tag) 
  59. >                {
  60. >                case T1:
  61. >                    foo(r.t1);
  62. >                etc....
  63. >        Assuming the template `exansion' occurs *after* the
  64. >        tagged pointer `expansion', the correct code would
  65. >        be generated.  I don't like heavy use of template 
  66. >        functions because I can't control what types my 
  67. >        template is called with.  Templates also don't allow
  68. >        for automatic type conversion.
  69.  
  70.     Yes, your choice.
  71.  
  72. >    2)    Tighten the relationship between tagged pointers and 
  73. >        tagged unions.  i.e. dereferencing a tagged pointer in
  74. >        a context where a tagged union of like types is expected
  75. >        yields a tagged union and taking the address of a tagged
  76. >        union yields a tagged pointer.  Then foo could be declared
  77. >        as taking a reference to a tagged union and foo(*r) would
  78. >        be valid.  I think there are some things wrong with this 
  79. >        idea, though I haven't thought it out.
  80.  
  81.     Pointer to tagged unions != tagged pointer. Have to think
  82. about it.
  83.  
  84. >    3)    Allow tagged references.
  85. >
  86. >IMHO, 3 is the cleanest solution (besides which, for the sake of symmetry
  87. >if we have tagged pointers we should have tagged references).
  88.  
  89.     Yes. Could be nice :-)
  90.  
  91. >
  92. >Shawn Willden
  93. >swillden@icarus.weber.edu
  94.  
  95.  
  96. -- 
  97. ;----------------------------------------------------------------------
  98.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  99.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  100. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  101.