home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!munnari.oz.au!metro!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU (John MAX Skaller)
- Subject: Re: Tagged Pointers
- Message-ID: <1992Aug12.142427.8090@ucc.su.OZ.AU>
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: MAXTAL P/L C/- University Computing Centre, Sydney
- References: <memo.565692@cix.compulink.co.uk> <1992Aug9.201515.7353@ucc.su.OZ.AU> <9222518.29850@mulga.cs.mu.OZ.AU>
- Date: Wed, 12 Aug 1992 14:24:27 GMT
- Lines: 66
-
- In article <9222518.29850@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
- >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- >
- >>>Ok, what about tagged references for ortogonality?
- >>
- >> And tagged values, right? (Also known as tagged unions).
- >>
- >> I originally put 'and you have tagged references just like
- >>tagged pointers (so I needn't describe them) execpt that the
- >>syntax is different' in my post.
- >>
- >> But now I don't think that you can HAVE tagged references.
- >>Tagged pointers are VARIABLES, like pointers. References are not,
- >>they cannot be changed. If you had tagged references you would knoy
- >>be able to use them where you coudl use a pointer:
- >>
- >> [T1, T2]& r;
- >> r.function();
- >>
- >>Am I wrong on this, do tagged references make sense?
- >
- >Yes, they do make sense.
- >
- >For example, although the tag cannot change, you can still pass a tagged
- >reference to a function that does not know what the tag is.
- >
-
- Tagged references make sense. My proposal for tagged pointers
- should be modified to remove the restriction that, for example
-
- [X,Y] *p;
- p->f();
-
- must have the same return type (i.e. X::f() and Y::f() need NOT have
- the same return type. One just duplicates the whole statement,
- and then factors out common subexpressions. ALternatively,
- differentiate the cases up the parse tree until a common return
- type is found---always at the statement level since a statement
- is implicitly
-
- (void) expr;
-
- This is the rvalue rule. For lvalues the rule is opposite,
- of the multiple cases one must be prefered.
-
- The idea of tagged pointer and references, though is NOT to declare
- functions taking them as arguments, so much as to declare multiple
- functions, one for each type:
-
- f(float*);
- f(int*);
- f(double*);
- f(char*);
-
- [float,int] *p;
- [int,double] *q;
-
- f(p); f(q);
-
- This is more efficient, achieving object code reuse.
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-