From -5823143061024840397
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fc772,cda54862ecb4a41f
X-Google-Attributes: gidfc772,public
X-Google-Thread: f78e5,cda54862ecb4a41f
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2001-08-27 08:02:18 PST
Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!portc03.blue.aol.com!news.gtei.net.MISMATCH!washdc3-snh1.gtei.net!denver-snf1.gtei.net!news.gtei.net!namche.sun.com!news2me.EBay.Sun.COM!engnews1.eng.sun.com!taumet!clamage
From: "Gaurav Sareen" <albelakela@hotmail.com>
Newsgroups: comp.std.c++,comp.lang.c++.moderated
Subject: Re: storage order of inherited classes
Date: 27 Aug 2001 14:55:43 GMT
Organization: Road Runner - Texas
Lines: 33
Approved: stephen.clamage@sun.com (comp.std.c++)
Message-ID: <XPai7.507226$lq1.100246902@typhoon.austin.rr.com>
References: <MpMh7.6544$3f.1248650@news2-win.server.ntlworld.com>
NNTP-Posting-Host: taumet.eng.sun.com
X-NNTP-Posting-Host: netlab.cs.rpi.edu
X-Original-Date: Sun, 26 Aug 2001 18:01:27 GMT
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated
	iQBVAwUAO4mVDEHMCo9UcraBAQHYWQH+Mm6VTUJgeO5Kdya5GUiF00RGUsobVGJM
	gZ6XthT/IiLwyrlprlIyvK/USUyreiCY9ND6ApZojbGh9EgkrTJKew==
	=P7OM
X-Approved-For-Group: hsutter@acm.org comp.lang.c++.moderated
Content-Length: 1417
X-Status: $$$$
X-UID: 0000000001
Originator: clamage@taumet
Xref: archiver1.google.com comp.std.c++:7176 comp.lang.c++.moderated:25425


> Im involved in optimising a few C++ classes that interface with OpenGL
> I was wondering if the memory storage order of class members is
> standardised ?

No its not. Its dependent on the compiler. Typically the base class part is
stored right before the derived class part in order to make the common casts
to base efficient, just like C:
Base* b;
Derived* d = new Derived;
b = d; //This operation is just assigning one register to another.

However C++ language features ( virtual functions, virtual inheritance and
multiple inheritance) are typically implemented in different ways by diff
compilers. If you are going to use one particular version of one particular
compiler on one particular platform, perhaps you can get by by some
hardcoded magic, which is not recommended.

This IMO is one of the big reasons why java can be "safer" than C++ is that
the runtime layout of the classes is fixed.



      [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ]
      [ about comp.lang.c++.moderated. First time posters: do this! ]

[ 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.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]




