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: <1992Aug13.082618.18274@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: <1992Aug9.201515.7353@ucc.su.OZ.AU> <1992Aug10.221849.19455@fcom.cc.utah.edu>
- Date: Thu, 13 Aug 1992 08:26:18 GMT
- Lines: 88
-
- In article <1992Aug10.221849.19455@fcom.cc.utah.edu> swillden@news.ccutah.edu (Shawn Willden) writes:
- >maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- >: In article <memo.565692@cix.compulink.co.uk> vadim@cix.compulink.co.uk writes:
- >: >[ deleted text]
- >: >
- >: >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 not
- >: be able to use them where you could use a pointer:
- >:
- >: [T1, T2]& r;
- >: r.function();
- >:
- >: Am I wrong on this, do tagged references make sense?
- >
- >Sure they make sense. Are they necessary? (Assuming tagged pointers
- >are). Look at the following.
-
- They're never *necessary*. But useful? and sound? and safe?
-
- >
- > void foo(const [T1, T2, T3]& r) // This idiom pops up now and then ;->
- > { // do something with r }
- >
- > void bar()
- > {
- > [T1, T2, T3]* r;
- > T1 t1;
- >
- > r= &t1;
- > foo(*r);
- > }
- >
- >I can see three ways to make this work:
- > 1) Make foo a template function (void foo(T& r)). If I
- > understood your proposal, dereferencing r would create
- > something like:
- > switch (r.tag)
- > {
- > case T1:
- > foo(r.t1);
- > etc....
- > Assuming the template `exansion' occurs *after* the
- > tagged pointer `expansion', the correct code would
- > be generated. I don't like heavy use of template
- > functions because I can't control what types my
- > template is called with. Templates also don't allow
- > for automatic type conversion.
-
- Yes, your choice.
-
- > 2) Tighten the relationship between tagged pointers and
- > tagged unions. i.e. dereferencing a tagged pointer in
- > a context where a tagged union of like types is expected
- > yields a tagged union and taking the address of a tagged
- > union yields a tagged pointer. Then foo could be declared
- > as taking a reference to a tagged union and foo(*r) would
- > be valid. I think there are some things wrong with this
- > idea, though I haven't thought it out.
-
- Pointer to tagged unions != tagged pointer. Have to think
- about it.
-
- > 3) Allow tagged references.
- >
- >IMHO, 3 is the cleanest solution (besides which, for the sake of symmetry
- >if we have tagged pointers we should have tagged references).
-
- Yes. Could be nice :-)
-
- >
- >Shawn Willden
- >swillden@icarus.weber.edu
-
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-