This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Strange behaviour in C++...
- To: gcc@gcc.gnu.org
- Subject: Re: Strange behaviour in C++...
- From: "Christopher R. Jones" <cj@interlog.com>
- Date: Wed, 25 Aug 1999 07:55:48 -0400
I am puzzled at the lack of attention this thread has received. There is
obviously some strange behavior with gcc 2.95.1 on Linux (at least Redhat
5.2):
Using a 180 Pentium Pro:
>From Solairs Intel, gcc 2.95.1, built with gcc 2.8:
Alfa 1=42
Alfa 2=42
BetaAlfa=42
Alfa 1=47
Alfa 2=47
GammaAlfa=47
AlfaGammaAlfa=47
>From Linux Redhat 5.2, gcc 2.95.1, built with egcs 1.1.2:
Alfa 1=42
Alfa 2=42
BetaAlfa=42
Alfa 1=47
Alfa 2=134580833
GammaAlfa=47
AlfaGammaAlfa=47
At 04:54 PM 8/24/99 +0200, Fredrik Öhrström wrote:
>
>The code below compiled with 2.95.1 (19990816)
>(on a RedHat 5.2 system i386) produces:
>
>Alfa 1=42
>Alfa 2=42
>BetaAlfa=42
>Alfa 1=47
>Alfa 2=134580865
>GammaAlfa=47
>AlfaGammaAlfa=47
>
>Shouldn't Alfa 2 be 47 in the second creation?
>
>Cheers
>Fredrik
>
>---------------------------------------------------------
>
>
>#include<iostream.h>
>
>struct Alfa
>{
> virtual int alfa() = 0;
>};
>
>struct Beta
>{};
>
>struct Gamma
>{};
>
>struct Alfa_i : public virtual Alfa
>{
> int a;
>
> Alfa_i (int aa) : a (aa)
> {
> }
>
> int alfa ()
> {
> return a;
> }
>};
>
>struct Beta_i : public virtual Beta,
> public Alfa_i
>{
> Beta_i (int bb) : Alfa_i (bb)
> {
> cerr << "Alfa 1=" << alfa ()<< endl;
> Alfa *a = this;
> cerr << "Alfa 2=" << a->alfa ()<< endl;
> }
>};
>
>struct Gamma_i : public virtual Gamma,
> public Beta_i
>{
> Gamma_i (int cc)
> : Beta_i (cc)
> {}
>};
>
>
>int main ()
>{
> Beta_i *b = new Beta_i (42);
> cerr << "BetaAlfa=" << b->alfa() << endl;
>
> Gamma_i *g = new Gamma_i (47);
> cerr << "GammaAlfa=" << g->alfa() << endl;
>
> Alfa *a = g;
> cerr << "AlfaGammaAlfa=" << a->alfa() << endl;
>}
>
>
>
>
>
Christopher R. Jones, P.Eng.
14 Oneida Avenue
Toronto, Ontario M5J 2E3
Tel. 416 203-7465
Fax. 416 203-3044
Email cj@interlog.com
Christopher R. Jones, P.Eng.
14 Oneida Avenue
Toronto, Ontario M5J 2E3
Tel. 416 203-7465
Fax. 416 203-3044
Email cj@interlog.com