Topic: Is the order of declaration of base classes significant?


Author: shashank@sashimi.wwa.com (Shashaanka)
Date: 1995/07/19
Raw View
raines@esaw01.SLAC.Stanford.EDU (Paul E. Raines) wrote:


>My question is in the following multiple inheritance example,

>  class Browser : public UIComponent, public FontClient {
>    . . .
>  };

>is the "this" for Browser's methods guaranteed to alway be equal
>to the same address of "this" for UIComponent's methods? In other
>words, is the storage for UIComponent always guaranteed to be at
>the top of the storage area of Browser?

No. Read ARM. Specific examples are discussed there. Language does not
guarantee any specific order for base class components in derived
classes. However, for specific compilers, it may be the same.

>I am writing a C++ library based on Doug Young's MotifApp. The
>UIComponent class has a method for getting X resources from the
>database and writing them to members of the class. This depends
>on offsets in memory in which this is used as the start.

>pr

>--
>_________________________________________________________________________
>Paul Raines  raines@slac.stanford.edu           415-926-4378
>Stanford Linear Accelerator    End Station A         E143 Collaboration
>http://www.slac.stanford.edu/~raines/index.html  PGP public key by finger







Author: shashank@sashimi.wwa.com (Shashaanka)
Date: 1995/07/19
Raw View
raines@esaw01.SLAC.Stanford.EDU (Paul E. Raines) wrote:


>My question is in the following multiple inheritance example,

>  class Browser : public UIComponent, public FontClient {
>    . . .
>  };

>is the "this" for Browser's methods guaranteed to alway be equal
>to the same address of "this" for UIComponent's methods? In other
>words, is the storage for UIComponent always guaranteed to be at
>the top of the storage area of Browser?

No. Read ARM. Specific examples are discussed there. Language does not
guarantee any specific order for base class components in derived
classes. However, for specific compilers, it may be the same.

>I am writing a C++ library based on Doug Young's MotifApp. The
>UIComponent class has a method for getting X resources from the
>database and writing them to members of the class. This depends
>on offsets in memory in which this is used as the start.

>pr

>--
>_________________________________________________________________________
>Paul Raines  raines@slac.stanford.edu           415-926-4378
>Stanford Linear Accelerator    End Station A         E143 Collaboration
>http://www.slac.stanford.edu/~raines/index.html  PGP public key by finger







Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/07/15
Raw View
raines@esaw01.SLAC.Stanford.EDU (Paul E. Raines) writes:


>My question is in the following multiple inheritance example,

>  class Browser : public UIComponent, public FontClient {
>    . . .
>  };

>is the "this" for Browser's methods guaranteed to alway be equal
>to the same address of "this" for UIComponent's methods?

No. Class layout is unspecified. Either base class might start
at the same address as Browser, or possibly neither one of them.
Portable code may make no assumptions about class layout. Even
different releases of the same compiler might use different
class layouts.
--
Steve Clamage, stephen.clamage@eng.sun.com





Author: raines@esaw01.SLAC.Stanford.EDU (Paul E. Raines)
Date: 1995/07/14
Raw View
My question is in the following multiple inheritance example,

  class Browser : public UIComponent, public FontClient {
    . . .
  };

is the "this" for Browser's methods guaranteed to alway be equal
to the same address of "this" for UIComponent's methods? In other
words, is the storage for UIComponent always guaranteed to be at
the top of the storage area of Browser?

I am writing a C++ library based on Doug Young's MotifApp. The
UIComponent class has a method for getting X resources from the
database and writing them to members of the class. This depends
on offsets in memory in which this is used as the start.

pr

--
_________________________________________________________________________
Paul Raines  raines@slac.stanford.edu           415-926-4378
Stanford Linear Accelerator    End Station A         E143 Collaboration
http://www.slac.stanford.edu/~raines/index.html  PGP public key by finger