From 316146929126129229
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,bed6baff9e441d5c
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-02-13 11:29:41 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: allan_w@my-dejanews.com (Allan W)
Newsgroups: comp.std.c++
Subject: Re: proposal: "virtual restrict" inheritance
Date: Thu, 13 Feb 2003 19:29:40 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 94
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <7f2735a5.0302131128.115b22fc@posting.google.com>
References: <5a0f3464.0302020455.25d887a9@posting.google.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1045164580 7920 10.0.0.1 (13 Feb 2003 19:29:40 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Thu, 13 Feb 2003 19:29:40 +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 18jP3C-00023b-00
	for mail2news@news.news.demon.net; Thu, 13 Feb 2003 19:29:39 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id GAA14746; Fri, 14 Feb 2003 06:29:34 +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: 13 Feb 2003 19:28:11 GMT
X-MailScanner: PASSED (v1.2.7 53836 h1DJSEQq067128 mailbox6.ucsd.edu)
X-Spam-Status: No, hits=-9.7 required=5.0
	tests=NOSPAM_INC,QUOTED_EMAIL_TEXT,REFERENCES,SPAM_PHRASE_02_03
	version=2.41
Xref: archiver1.google.com comp.std.c++:17945

dlagno@mail.nnov.ru (Denis Lagno) wrote

> [Problem description]
> Imagine that you have typical rhomb shaped inheritance framework
> 
>      B
>    /   \
>    C   D
>    \   /
>      X
> 
> If compiler knows that nothing is grafted badly to this structure in
> other translation units, it can implement one of inheritances
> C:virtual B or D:virtual B not as it usually does -- thru pointer and
> indirect access but directly thru statically known offset.
> 
> But since compiler sees only one translation unit at a time it cannot
> do such optimization.

What does it mean for a structure to be "grafted badly?" As opposed
to "grafted well?" I assume "grafted" means "added to the class
heirarchy" i.e. a derived class. But what makes this good or bad?

> [Proposed solution]
> add "virtual restrict" inheritance.

> "virtual restrict" inheritance logically shall be the same as usual
> "virtual" but with one restriction -- if for any derived class some
> base class occurs more than 1 time as "virtual restrict" then the
> program is ill-formed.

So one class gets "virtual restrict" and the others just get "virtual."
Is that right?

What would the compiler do differently for a "virtual restrict"
derivation?

> So changes to standard required are very small and local and without
> possible interference with other language features -- because
> semantically "virtual restrict" shall everywhere act as usual
> "virtual".  But beforementioned restriction enables compiler to
> optimize virtual inheritance.

How?

> I assumed that keyword "restrict" already included in C99 so it is
> good to reuse it in another sense in another place.
> 
> [example]
> former inheritance framework may be now written as:
> 
> class B { ... };
> 
> class C: public virtual B { ... };
> 
> class D: public virtual restrict B { ... };
> 
> class X: public C, public D { ... };
> 
> I'll be glad to hear comments.

I don't understand what optimization this makes possible. I suppose
you're saying that the compiler could arrange class B and D next to
each other, so that class D doesn't need to use a pointer to find
the members of B. But surely all the other classes still need that
pointer. Also, what happens if something else derives from C and/or
D? What happens if something derives from both X and Y, where Y
also derives from D?

      B
     / \
    C   D
     \ / \
      X   Y
       \ /
        W

class B { ... };
class C: public virtual B { ... };
class D: public virtual restrict B { ... };
class X: public C, public D { ... };
class Y: public D { ... };
class W: public X, public Y { ... };

Without the "restrict" keyword, we have two instances of D, but
only one instance of B. What happens with the restrict keyword?
Why is this good?

---
[ 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                       ]



