From 8905305610356699342
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:17 PST
Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!feed.news.qwest.net!namche.sun.com!news2me.EBay.Sun.COM!engnews1.eng.sun.com!taumet!clamage
From: "James Russell Kuyper Jr." <kuyper@wizard.net>
Newsgroups: comp.std.c++,comp.lang.c++.moderated
Subject: Re: storage order of inherited classes
Date: 27 Aug 2001 14:55:42 GMT
Organization: Posted via Supernews, http://www.supernews.com
Lines: 41
Approved: stephen.clamage@sun.com (comp.std.c++)
Message-ID: <3B88CE59.624F4BDD@wizard.net>
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 06:24:25 -0400
X-Submission-Address: c++-submit@netlab.cs.rpi.edu
X-Auth: PGPMoose V1.1 PGP comp.lang.c++.moderated
	iQBVAwUAO4mU+UHMCo9UcraBAQHUigH9FCTy6Ld9OdDfdQBrWdFPm+9/nB3GoldJ
	Pw+KF2eYoD2EvIVqpDBRvfsxzT9P37Cq0QTX1JoMkTr54b1YgTNYQA==
	=cFqp
X-Approved-For-Group: hsutter@acm.org comp.lang.c++.moderated
Content-Length: 1556
X-Status: $$$$
X-UID: 0000000001
Originator: clamage@taumet
Xref: archiver1.google.com comp.std.c++:7175 comp.lang.c++.moderated:25424


Fray Bentos wrote:
>
> Hey peeps.
>
> 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 ?

Yes, but only to a degree:

9.2p12: "Nonstatic data members of a (non-union) class declared without
an intervening _access-specifier_ are allocated so that later members
have higher addresses within a class object. The order of allocation of
nonstatic data members separated by an _access-specifier_ is unspecified
(11.1). Implementation alignment requirements might cause two adjacent
members not to be allocated immediately after each other; so might
requirements for space for managing virtual functions (10.3) and virtual
base classes (10.1)."

10.1p3: "The order in which the base class subobjects are allocated in
the most derived object (1.8) is unspecified. ..."

> Will the array j from the derived class B always be stored before i from the
> base class A ?

Because of 10.1p3, there's no guarantee about the position of j relative
to i.



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




