home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!caen!hellgate.utah.edu!fcom.cc.utah.edu!swillden
- From: swillden@news.ccutah.edu (Shawn Willden)
- Subject: Re: Tagged Pointers
- Message-ID: <1992Aug17.174931.1376@fcom.cc.utah.edu>
- Sender: news@fcom.cc.utah.edu
- Organization: University of Utah Computer Center
- X-Newsreader: Tin 1.1 PL3
- References: <1992Aug14.234242.8418@ucc.su.OZ.AU>
- Date: Mon, 17 Aug 92 17:49:31 GMT
- Lines: 79
-
- maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
- : In article <1992Aug13.173401.14944@fcom.cc.utah.edu> swillden@news.ccutah.edu (Shawn Willden) writes:
- : >That's what I understood from your previous posts (TU*!=TP) and I was
- : >suggesting that maybe there is a good argument for making this so.
- : >What are the arguments against it?
- : >
- :
- : There's not so much an argument against it as a simple fact
- : that th're different. The tagged pointer has the tag in the pointer
- : (conceptually at least). It is a pointer that can point to one
- : of several types.
- :
- : A tagged union has the tag in the union. It is an object
- : of one of several types. A pointer to
- : a tagged union is an *ordinary* pointer.
- :
- : Tagged pointers are a special case of tagged unions.
- : You can of course have a pointer to a tagged pointer, etc.
- : You wouldnt want that to be a tagged pointer would you?
- : Or perhaps you would?
-
- No, I don't think so. Not if we want to allow:
-
- [T1,T2,T3]** foo = new [T1,T2,T3]*[NUM_ELEMS];
-
- (if I understand your syntax). What I mean is a ordinary pointer
- to an array of tagged pointers.
-
- : It all depends on whether tagged pointers are a genuine
- : type or not. If it is, all the above things must be distinct.
- : If not (I suggested not in my post) then maybe we can make
- : a pointer to a tagged union work as if it were a tagged
- : pointer. This would homogenise the interface. More work
- : for the compiler, less for the programmmer. Less control
- : for the programmer too.
-
- Hmmm. It appears I didn't explain myself very well because that is
- precisely what *I* was suggesting. I suppose the difference lies in
- my consideration of TP's and TU's as different types but (as I said)
-
- 1) *TP yields a TU
- 2) &TU yields a TP
-
- whereas you suggested that they not be actual *types* but that we
- make them work like the above anyway. Same effect, different words.
- Have I got this right?
-
- : So the issue is whether a tagged pointer is a proper type
- : or just a sort of syntactic sugaring that supports a new
- : mechanism for genericity. My thinking was the latter.
-
- I think your thinking is better :-) TP couldn't be a proper type
- anyway. If anything, TP would be a *family* of types.
-
- : Any comments?
-
- Getting back to the question that started this exchange (should we have
- tagged references?), I think that they're probably unnecessary for the
- case I was presenting (by which I mean that they don't greatly simplify
- anything). If I have a TP and wish to pass a reference to what it points
- to to a function I can just say:
-
- void foo([T1,T2,T3]& fred) // fred is a ref to a TU, not a tagged ref.
- {...}
-
- void bar();
- {
- [T1,T2,T3]* barney;
- ...
- foo(*barney); // *barney is a TU, foo gets a ref to it.
- }
-
- at least that is what the programmer may think. In fact TU and TP are not
- types but the syntax of the sugar looks right. Actually, does it really
- matter whether we call [T1,T2,T3]& a ref to a tagged union or a tagged
- ref?
-
- Shawn Willden
- swillden@icarus.weber.edu
-