I just read something interesting in one of the PDFs located here: http://www.cs.wustl.edu/~schmidt/C++/ Sorry, I don't recall which file it
was, and I'm too lazy to dig it up again ;) It says that the compiler is
obligated to arrange the memory of this class in declaration order:
class InOrder{
public:
int a;
int b;
int c;
};
But a compiler is free to rearrange this:
class AnyOrder{
public: int a;
public: int b;
public: int c;
};
Anybody know about this?
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell 10 1824
Steven T. Hatton wrote: I just read something interesting in one of the PDFs located here: http://www.cs.wustl.edu/~schmidt/C++/ Sorry, I don't recall which file it was, and I'm too lazy to dig it up again ;) It says that the compiler is obligated to arrange the memory of this class in declaration order:
class InOrder{ public: int a; int b; int c; };
But a compiler is free to rearrange this:
class AnyOrder{ public: int a; public: int b; public: int c; };
Anybody know about this?
never heard about that, as far as i know those two are the same,
G
-- http://www.kolumbus.fi/bob.smith
The allocation for member variables, which are not separated by a
different access specifier, will be in the same order as their
declaration in the class; this is to provide compatibility with C code.
In the above example, the memory layout of an object of InOrder will be
contiguous for a, b, c.
Moreover, if we have protected and also private members, the memory
layout can reorder/group the member variables as follows, irrespective
of their declaration order in the class:
memory layout:
int a, b, c; // public members first
int d, e, f; // protected
int h, i, j; // private in the last.
this is to provide minimal recompilation to the client code whenever
there is any change to the private part/data of the class used.
This is not the only method the compiler follows but this is one of the
many tricks.
Bob Smith wrote: Steven T. Hatton wrote:
I just read something interesting in one of the PDFs located here: http://www.cs.wustl.edu/~schmidt/C++/ Sorry, I don't recall which file it was, and I'm too lazy to dig it up again ;) It says that the compiler is obligated to arrange the memory of this class in declaration order:
class InOrder{ public: int a; int b; int c; };
But a compiler is free to rearrange this:
class AnyOrder{ public: int a; public: int b; public: int c; };
Anybody know about this? never heard about that, as far as i know those two are the same,
G
It looks like Schmidt's right, unless the specification has changed. See
TC++ARM §9.2 page 173.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Steven T. Hatton wrote: It looks like Schmidt's right, unless the specification has changed. See TC++ARM §9.2 page 173.
ARM is a bit outdated.
Look up in the standard:
§11.1.2.
and
§9.2.12.
leonardo77 wrote: Steven T. Hatton wrote: It looks like Schmidt's right, unless the specification has changed. See TC++ARM §9.2 page 173.
ARM is a bit outdated. Look up in the standard: §11.1.2. and §9.2.12.
So the specification hasn't changed in this regard.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
"Steven T. Hatton" <ch********@germania.sup> wrote in message
news:nd********************@speakeasy.net leonardo77 wrote:
Steven T. Hatton wrote: It looks like Schmidt's right, unless the specification has changed. See TC++ARM §9.2 page 173.
ARM is a bit outdated. Look up in the standard: §11.1.2. and §9.2.12.
So the specification hasn't changed in this regard.
I think that 9.2.14 also needs to be looked at. It suggests to me that your
InOrder and AnyOrder must be layout compatible. Alas, the standard doesn't
seem to give a clear statement of what layout-compatible means. As a
practical matter, I would be amazed if any compiler laid the two structs out
in a different order, given that the access specifiers are really a
degenerate case.
--
John Carson
John Carson wrote: "Steven T. Hatton" <ch********@germania.sup> wrote in message news:nd********************@speakeasy.net leonardo77 wrote:
Steven T. Hatton wrote: It looks like Schmidt's right, unless the specification has changed. See TC++ARM §9.2 page 173.
ARM is a bit outdated. Look up in the standard: §11.1.2. and §9.2.12.
So the specification hasn't changed in this regard.
I think that 9.2.14 also needs to be looked at. It suggests to me that your InOrder and AnyOrder must be layout compatible. Alas, the standard doesn't seem to give a clear statement of what layout-compatible means. As a practical matter, I would be amazed if any compiler laid the two structs out in a different order, given that the access specifiers are really a degenerate case.
I too would be quite surprised if it made a difference. The only reason I
could see for that would be some kind of space optimization if the members
were of different type. It does, however, suggest that
class Klass{
public:
int a;
private:
int b;
public:
int c;
};
might get re-suffled.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Steven T. Hatton wrote: So the specification hasn't changed in this regard.
Sorry! I was a bit confused about your statement.
"Steven T. Hatton" <ch********@germania.sup> wrote in message
news:1M********************@speakeasy.net John Carson wrote:
I think that 9.2.14 also needs to be looked at. It suggests to me that your InOrder and AnyOrder must be layout compatible. Alas, the standard doesn't seem to give a clear statement of what layout-compatible means. As a practical matter, I would be amazed if any compiler laid the two structs out in a different order, given that the access specifiers are really a degenerate case.
I too would be quite surprised if it made a difference. The only reason I could see for that would be some kind of space optimization if the members were of different type. It does, however, suggest that
class Klass{ public: int a; private: int b; public: int c; };
might get re-suffled.
That is certainly a possibility.
--
John Carson
leonardo77 wrote: Steven T. Hatton wrote: So the specification hasn't changed in this regard.
Sorry! I was a bit confused about your statement.
Nothing to apologize for. You cleared up the matter. The Standard could
well have changed. I was simply communicating the fact to the rest of the
folks here.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Terje Slettebø |
last post by:
Well, as is customary when you're new to a group, you tend to post quite a
bit, :) so here's one more. Some things I've been wondering about with PHP
(5).
Today, I worked on an implementation of...
|
by: Gabriel Zachmann |
last post by:
Is there any generic way to use C++ libraries from within Python.
I seem to recall that there are tools to generate wrappers for C-libraries
semi-automatically.
But those were still way too...
|
by: BDob |
last post by:
Standard documents "Access control is not considered in determining
overriding."
To further explain what's puzzling me, I put up an example below:
class Base
{
public:
virtual void...
|
by: Martin Vorbrodt |
last post by:
say i have this:
union U {
public:
U(int a) : x(a) {}
protected:
int x, y, z;
};
why is the protected access even allowed for unions? no inheritance can take
|
by: vipul DotNet |
last post by:
hi,
which all are the access specifiers in vb.net
thank you
vipul
| |
by: Tapeesh |
last post by:
I have a following piece of code. The code was compiled using g++
class A
{
public :
virtual void fn() = 0;
};
class B: virtual private A
{
|
by: Henryk |
last post by:
I have something like
class Params {
public:
const static char nOne = 1;
const static int nTwo = 2;
const static char nThree = 3;
};
This is just a wrapper for globally used parameters in...
|
by: Kavya |
last post by:
int main (){
int a={{1,2,3},{4,5,6}};
int (*ptr)=a;
/* This should be fine and give 3 as output*/
printf("%d\n",(*ptr));
++ptr;
|
by: prakashwadhwani |
last post by:
Hi !! I'm about to develop a new project for a client.
Should I go about it in Access 2003 or 2007 ? Purchasing it either
for me or for my client is not a major consideration here ... what I'd...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |