From 4453684935260099539
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,18c6d861cef54158
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-01-02 12:24:51 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: danielgutson@hotmail.com (danielgutson@hotmail.com)
Newsgroups: comp.std.c++
Subject: Re: automatic downcast support through function parameters
Date: Thu, 2 Jan 2003 20:24:44 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 91
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <23478c42.0301020923.79359e66@posting.google.com>
References: <23478c42.0212310830.23dbc580@posting.google.com> <3E120608.6060608@tellabs.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1041539084 16848 10.0.0.1 (2 Jan 2003 20:24:44 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 2 Jan 2003 20:24:44 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 18UBtS-0004Nb-00
	for mail2news@news.news.demon.net; Thu, 02 Jan 2003 20:24:42 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id HAA07975; Fri, 3 Jan 2003 07:24:38 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 2 Jan 2003 17:23:47 GMT
X-Spam-Status: No, hits=-8.4 required=5.0
	tests=FORGED_HOTMAIL_RCVD,NOSPAM_INC,QUOTED_EMAIL_TEXT,
	      REFERENCES,SPAM_PHRASE_03_05
	version=2.41
Xref: archiver1.google.com comp.std.c++:16658

Daniel.Miller@tellabs.com ("Dan'l Miller") wrote in message news:<3E120608.6060608@tellabs.com>...
> danielgutson@hotmail.com wrote:
> > People: I'd like to ask about the feasibility of this:
> > automatic downcast during function calls.
> > let's have:
> >  struct Base{};
> >  struct Der : Base{};
> > 
> >  void g(Base* b);
> >  void g(Der* d);
> > 
> >  void f(upcasted Base* b)    // see below
> >  {
> >    g(b);
> >  }
> > 
> >  void main(void)
> >  {
> >     Der d;
> >     f(&d);
> >  }
> > 
> >  - The idea here is that f ignores the function that will be finally
> >  invoked, but knows that the pointer was upcasted ('upcasted'
> > keyword).
> >  Then, the function accepting the most derived class (closest to the
> >  original type) will be invoked, in this case: g(Der*).
> > 
> > The 'spirit' of this is to recover specificity: in the process flow:
> >   main -> f -> g
> > specificity(main) = specificity(g) > specificity(f)
> > and this would be an automatic way of recoviring specificity at g,
> > without loosing generality at f.
> > 
> >  What you think?
> 
>    I think that this works well at compile-time only 1) if one has a single 
> compilation unit or 2) if one has global analysis among separate compilation 
> units.  In practice "compilation unit" normally corresponds to a .c/.cpp/.cxx/.C 
> file which begets a .o/.obj file.
> 
>    Because C's (and thus C++'s) compilation model is predicated on separate 
> compilation, this proposed feature is in turn predicated on the hypothetical 
> removal of separate compilation from C++/C.  Such removal of the 
> separate-compilation axiom appears quite unlikely to me in the foreseeable future.
> 
>    I think that human-authored code can be written to 
> overtly/manually/nonautomatically accomplish this via RTTI at run-time.
> 
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]

First of all, thanks for your answers.

Two things:

1) [To Kalle]: Yes, I'm talking about the second: a kind of condition
using RTTI. The advantage -and I'm not the best for asserting this as
far as I'm not in quality of implementations- is that -I think- this
can be achieved using a reduced set of RTTI primitives. I think, that
in fact RTTI is no needed (as a whole), despite any run time
information is needed in some kind. I think that this can be achieved
just with some additional entry in the v-table.
What if a null pointer is passed: the null pointer contains no
information, what means that it wasn't upcasted, it's just an
'original null pointer to base', then the g(Base*) should be called
(btw, your 'else' works).

2) About separated compilation units: I think that there is no need of
a whole program analysis (am I getting your point?), as far as, as I
think above, this can be achieved with an additional entry in the
vtables, and any indirection mechanism using that entry.
Do you think it is possible in this way?

Before I mess in the implementation of such mechanism, please provide
me some
feedback about the usage. What do you think about the concept I
describe?

Thanks!
   Daniel.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



