home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12289 < prev    next >
Encoding:
Text File  |  1992-08-12  |  2.6 KB  |  79 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: <1992Aug12.142427.8090@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: <memo.565692@cix.compulink.co.uk> <1992Aug9.201515.7353@ucc.su.OZ.AU> <9222518.29850@mulga.cs.mu.OZ.AU>
  10. Date: Wed, 12 Aug 1992 14:24:27 GMT
  11. Lines: 66
  12.  
  13. In article <9222518.29850@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  14. >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  15. >
  16. >>>Ok, what about tagged references for ortogonality?
  17. >>
  18. >>    And tagged values, right?  (Also known as tagged unions).
  19. >>
  20. >>    I originally put 'and you have tagged references just like
  21. >>tagged pointers (so I needn't describe them) execpt that the
  22. >>syntax is different' in my post.
  23. >>
  24. >>    But now I don't think that you can HAVE tagged references.
  25. >>Tagged pointers are VARIABLES, like pointers. References are not,
  26. >>they cannot be changed. If you had tagged references you would knoy
  27. >>be able to use them where you coudl use a pointer:
  28. >>
  29. >>    [T1, T2]& r;
  30. >>    r.function();
  31. >>
  32. >>Am I wrong on this, do tagged references make sense?
  33. >
  34. >Yes, they do make sense.
  35. >
  36. >For example, although the tag cannot change, you can still pass a tagged
  37. >reference to a function that does not know what the tag is.
  38. >
  39.  
  40.     Tagged references make sense. My proposal for tagged pointers
  41. should be modified to remove the restriction that, for example
  42.  
  43.     [X,Y] *p;
  44.     p->f();
  45.  
  46. must have the same return type (i.e. X::f() and Y::f() need NOT have
  47. the same return type. One just duplicates the whole statement,
  48. and then factors out common subexpressions. ALternatively,
  49. differentiate the cases up the parse tree until a common return
  50. type is found---always at the statement level since a statement 
  51. is implicitly
  52.  
  53.     (void) expr;
  54.  
  55. This is the rvalue rule. For lvalues the rule is opposite,
  56. of the multiple cases one must be prefered.
  57.  
  58. The idea of tagged pointer and references, though is NOT to declare
  59. functions taking them as arguments, so much as to declare multiple
  60. functions, one for each type:
  61.  
  62.     f(float*);
  63.     f(int*);
  64.     f(double*);
  65.     f(char*);
  66.  
  67.     [float,int] *p;
  68.     [int,double] *q;
  69.  
  70.     f(p); f(q);
  71.  
  72. This is more efficient, achieving object code reuse.
  73.  
  74. -- 
  75. ;----------------------------------------------------------------------
  76.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  77.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  78. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  79.