Hi, I am planning to study how we can implement things that we implement
in c++ in c and using a bit asm also. First thing i want to know is
about class and struct difference. How is the private and public part
implemented in the c++ exactly or how is the internal representation
done. I tried to analise the ASM file produ ced my the VC++ compil er.
But there i wrote the following code class t{ private: __int8 i;
public: void valF(); }; int main(){ t dat; t dat1; t p; dat.valF();
p.valF(); dat1. valF(); return 1; } void t::v alF(){ i=3; return ; } in
the above class "t" i changed the specif ier of "i" from private to
public. but in both cases th e ASM code generated was same. Even the
exe file was same.Then how in the ru n time it knows which data is
private and which data is public. Is is implem ented by the runtime
libraries? or how? is there any site or book from which i can ge t more
info on it? Please let me know this first case.Hos can i im plement this
private and public thing in C and if required some ASM inline a lso. I
want to use a pure C compiler for this not a C++ compiler.How is it r
epresented by the c++ compiler in translation to intermediate stage.



--
DeltaOne
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Re: C++ in ternms of C by abc

abc
Thu Apr 21 02:31:38 CDT 2005

>
> Hi, I am planning to study how we can implement things that we implement
> in c++ in c and using a bit asm also. First thing i want to know is
> about class and struct difference. How is the private and public part
> implemented in the c++ exactly or how is the internal representation
> done. I tried to analise the ASM file produ ced my the VC++ compil er.
> But there i wrote the following code class t{ private: __int8 i;
> public: void valF(); }; int main(){ t dat; t dat1; t p; dat.valF();
> p.valF(); dat1. valF(); return 1; } void t::v alF(){ i=3; return ; } in
> the above class "t" i changed the specif ier of "i" from private to
> public. but in both cases th e ASM code generated was same. Even the
> exe file was same.

Yes, the "private" and "public" are same in fact.


> Then how in the ru n time it knows which data is
> private and which data is public.

In run time ,they are same. That is to say, you can visit private variable
of class exported by a dll by change the header file from private to public.
The only function of keyword private is to tell compiler,"hey, do not let
the code compile over."

> Is is implem ented by the runtime
> libraries? or how? is there any site or book from which i can ge t more
> info on it? Please let me know this first case.Hos can i im plement this
> private and public thing in C and if required some ASM inline a lso. I
> want to use a pure C compiler for this not a C++ compiler.How is it r
> epresented by the c++ compiler in translation to intermediate stage.
>

You can translate C code to C++ by ignore private and public.
Of course ,class member functions have to be changed to global functions.


>
>
> --
> DeltaOne
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>
>
>



Re: C++ in ternms of C by Eberhard

Eberhard
Thu Apr 21 02:48:09 CDT 2005

DeltaOne schrieb/wrote:

> Then how in the ru n time it knows which data is
> private and which data is public.

There is no case where the executable needs to know whether a member is
private or public. That distinction can and must be made at compile time.

Re: C++ in ternms of C by John

John
Thu Apr 21 02:49:18 CDT 2005

"DeltaOne" <DeltaOne.1ntz5w@mail.codecomments.com> wrote in message
news:DeltaOne.1ntz5w@mail.codecomments.com
> Hi, I am planning to study how we can implement things that we
> implement in c++ in c and using a bit asm also. First thing i want to
> know is about class and struct difference. How is the private and
> public part implemented in the c++ exactly or how is the internal
> representation done. I tried to analise the ASM file produ ced my the
> VC++ compil er. But there i wrote the following code class t{
> private: __int8 i; public: void valF(); }; int main(){ t dat; t dat1;
> t p; dat.valF(); p.valF(); dat1. valF(); return 1; } void t::v alF(){
> i=3; return ; } in the above class "t" i changed the specif ier of
> "i" from private to public. but in both cases th e ASM code generated
> was same. Even the exe file was same.Then how in the ru n time it
> knows which data is private and which data is public. Is is implem
> ented by the runtime libraries? or how? is there any site or book
> from which i can ge t more info on it? Please let me know this first
> case.Hos can i im plement this private and public thing in C and if
> required some ASM inline a lso. I want to use a pure C compiler for
> this not a C++ compiler.How is it r epresented by the c++ compiler in
> translation to intermediate stage.

What makes you think that there is any runtime enforcement of private and
public? If an attempt is made to access private data from a scope that is
not allowed such access, then the code will fail to compile. If a program
compiles, then all accesses are known to be legal, so there is no need to
keep a record of access rights in the .exe file. I believe that it is
possible for a compiler to incorporate access data in its output, but I
believe VC++ does not.

If you wish to make some security-based argument in favour of runtime
enforcement of access, then you need to know that private access is not a
security measure. It is an aid to good programming style only.

The following article describes the VC++ object model. It is a little old,
but I believe it is still largely correct.

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarvc/html/jangrayhood.asp


--
John Carson


Re: C++ in ternms of C by Doug

Doug
Thu Apr 21 09:50:01 CDT 2005

On Thu, 21 Apr 2005 00:56:05 -0500, DeltaOne wrote:

> Hi, I am planning to study how we can implement things that we implement
> in c++ in c and using a bit asm also. First thing i want to know is
> about class and struct difference. How is the private and public part
> implemented in the c++ exactly or how is the internal representation
> done. I tried to analise the ASM file produ ced my the VC++ compil er.
> But there i wrote the following code class t{ private: __int8 i;
> public: void valF(); }; int main(){ t dat; t dat1; t p; dat.valF();
> p.valF(); dat1. valF(); return 1; } void t::v alF(){ i=3; return ; } in
> the above class "t" i changed the specif ier of "i" from private to
> public. but in both cases th e ASM code generated was same. Even the
> exe file was same.Then how in the ru n time it knows which data is
> private and which data is public. Is is implem ented by the runtime
> libraries? or how? is there any site or book from which i can ge t more
> info on it? Please let me know this first case.Hos can i im plement this
> private and public thing in C and if required some ASM inline a lso. I
> want to use a pure C compiler for this not a C++ compiler.How is it r
> epresented by the c++ compiler in translation to intermediate stage.

In addition to the Jan Gray article John linked to, I think your studies
would be helped immensely by a couple of books:

The Annotated C++ Reference Manual (Paperback)
by Margaret A. Ellis, Bjarne Stroustrup
http://www.amazon.com/exec/obidos/tg/detail/-/0201514591

Inside the C++ Object Model (Paperback)
by Stanley B. Lippman
http://www.amazon.com/exec/obidos/tg/detail/-/0201834545

--
Doug Harrison
Microsoft MVP - Visual C++

Re: C++ in ternms of C by Alexander

Alexander
Thu Apr 21 10:26:33 CDT 2005

Access qualifier can be a part of a mangled (linker-visible) member function
name, as it is with VC. In other words, you won't be able to link your
executable with a library, if it was compiled with different access of
member functions.

"abc" <abc@263.net> wrote in message
news:epipkQkRFHA.2664@TK2MSFTNGP15.phx.gbl...
> >
>
> Yes, the "private" and "public" are same in fact.
>
>
>> Then how in the ru n time it knows which data is
>> private and which data is public.
>
> In run time ,they are same. That is to say, you can visit private variable
> of class exported by a dll by change the header file from private to
> public.
> The only function of keyword private is to tell compiler,"hey, do not let
> the code compile over."
>



Re: C++ in ternms of C by Mark

Mark
Thu Apr 21 13:00:56 CDT 2005

A class and a structure are effectivly the same in terms of code once
compiled.

A class has its member variables,

Class A
{
public:
int b, c, d;
private:
double e, f;
};

struct tagA
{
int b, c, d;
double e, f;
};


Each of these is represented in memory as

Class [b][c][d][ e ][ f ]
Struct [b][c][d][ e ][ f ]

OOP is implimented by using the same kind of offsets as those used when
accessing the stack for a function.

You begin with the start point, in this case the first byte of 'b' in both
cases. We consider this the base.

If we want to access c, we access the memory location [base + 4] where 4 is
the sizeof(int), likewise to access d we do [base + 8].

In the case of a class, we have functions that are 'owned' by the class,
this is basically the same as saying: we are going to have a set of
functions, only accessable through a certain namespace, and for each of
these functions we are going to always pass it the base. As we saw above the
[base] can then be used to access the variables regarding a certain instance
of that class.

So if we have

class A
{
public:
int b, c, d;
int total( ) {
return b + c + d;
}
};

When we call total we actually call it along the lines of:
int total(&instance)

total then becomes:
return *[instance] + *[instance + 1] + *[instance + 2];

Using pointer arithmatic we know that this is actually instance, instance +
4 and instance + 8, due to the sizeof int being 4.

---------------------------

To consider the other aspects of OOP, we obviously have public, private and
protected; these are to cause code to be more secure, prevent the fiddling
by other classes and to impliment a much more powerful and descriptive
structure to a class. These are of course, completle nonsense to the linker,
the compiler performs these checks to tell us that our code conforms to the
design specification of the class (for example, not changing the member
variable 'int m_Count' directly when we should have to call the public 'int
IncrementCount( )'.

You can consider though, when exporting DLL's and functions, the linker will
utilise these to know which to add to the exports table and which not to.

There is also the consideration of virtual functions, for these the calling
function needs to know which of the class methods (which in assembly code
are all accessable anyway) to call, for this we need a special lookup
table - this is stored elsewhere in the programs data for each individual
class (not instance of the class).

----------------------------

In short, imagine the compiler ripping all of the functions out of a class,
and making them global prefixed by your class name, say:

class CApple
{
private:
int munchy;
int colour;

public:
int GetMunchy( ) { return munchy; }
};

The compiler would turn this into CApple_GetMunchy, or, more specifically
something along the lines of:

CApple::Get@mu@chy, a mangled name. This would be global, so if we went:
CApple apple;
/* something extra to set muchyness */
printf( "%d", apple.GetMunchy( ) );

We actually call the global function CApple::Get@mu@chy, passing it the
perameter &apple.

Of course, at linker stage, CApple::Get@mu@chy just becomes an address,
unless kept in the export table.

Thats my best effort anyway, I HOPE it is correct :)

--
- Mark Randall
http://zetech.swehli.com

"DeltaOne" <DeltaOne.1ntz5w@mail.codecomments.com> wrote in message
news:DeltaOne.1ntz5w@mail.codecomments.com...
>
> Hi, I am planning to study how we can implement things that we implement
> in c++ in c and using a bit asm also. First thing i want to know is
> about class and struct difference. How is the private and public part
> implemented in the c++ exactly or how is the internal representation
> done. I tried to analise the ASM file produ ced my the VC++ compil er.
> But there i wrote the following code class t{ private: __int8 i;
> public: void valF(); }; int main(){ t dat; t dat1; t p; dat.valF();
> p.valF(); dat1. valF(); return 1; } void t::v alF(){ i=3; return ; } in
> the above class "t" i changed the specif ier of "i" from private to
> public. but in both cases th e ASM code generated was same. Even the
> exe file was same.Then how in the ru n time it knows which data is
> private and which data is public. Is is implem ented by the runtime
> libraries? or how? is there any site or book from which i can ge t more
> info on it? Please let me know this first case.Hos can i im plement this
> private and public thing in C and if required some ASM inline a lso. I
> want to use a pure C compiler for this not a C++ compiler.How is it r
> epresented by the c++ compiler in translation to intermediate stage.
>
>
>
> --
> DeltaOne
> ------------------------------------------------------------------------
> Posted via http://www.codecomments.com
> ------------------------------------------------------------------------
>
>
>



Re: C++ in ternms of C by Severian

Severian
Thu Apr 21 13:21:22 CDT 2005

On Thu, 21 Apr 2005 00:56:05 -0500, DeltaOne
<DeltaOne.1ntz5w@mail.codecomments.com> wrote:

>
>Hi, I am planning to study how we can implement things that we implement
>in c++ in c and using a bit asm also. First thing i want to know is
>about class and struct difference. How is the private and public part
>implemented in the c++ exactly or how is the internal representation
>done. I tried to analise the ASM file produ ced my the VC++ compil er.
>But there i wrote the following code class t{ private: __int8 i;
>public: void valF(); }; int main(){ t dat; t dat1; t p; dat.valF();
>p.valF(); dat1. valF(); return 1; } void t::v alF(){ i=3; return ; } in
>the above class "t" i changed the specif ier of "i" from private to
>public. but in both cases th e ASM code generated was same. Even the
>exe file was same.Then how in the ru n time it knows which data is
>private and which data is public. Is is implem ented by the runtime
>libraries? or how? is there any site or book from which i can ge t more
>info on it? Please let me know this first case.Hos can i im plement this
>private and public thing in C and if required some ASM inline a lso. I
>want to use a pure C compiler for this not a C++ compiler.How is it r
>epresented by the c++ compiler in translation to intermediate stage.

Most of the original C++ compilers converted C++ to C, rather than
directly to machine code. If any of these are still available, you may
want to have a look at their output to help understand the C++ object
model, though the generated C code may not be designed to be
particularly readable, and they won't support later C++ additions,
such as templates.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.

Re: C++ in ternms of C by Eugene

Eugene
Thu Apr 21 19:26:44 CDT 2005

Mark Randall wrote:
> A class and a structure are effectivly the same in terms of code once
> compiled.
>
> A class has its member variables,
>
> Class A
> {
> public:
> int b, c, d;
> private:
> double e, f;
> };
>
> struct tagA
> {
> int b, c, d;
> double e, f;
> };
>
>
> Each of these is represented in memory as
>
> Class [b][c][d][ e ][ f ]

That's one possibility. Another is

[e][f][b][c][d]

IIRC members are required to follow each other within a single
public/private/protected block. The blocks themselves can be positioned in
any order.
Practically, I don't know of any compiler that makes use of this freedom.

--
Eugene
http://www.gershnik.info



Re: C++ in ternms of C by John

John
Thu Apr 21 19:44:28 CDT 2005

"Severian [MVP]" <severian@chlamydia-is-not-a-flower.com> wrote in
message news:gjrf61p3l5erbl9n8c5k58sa5lf3lqicr2@4ax.com
>
> Most of the original C++ compilers converted C++ to C, rather than
> directly to machine code. If any of these are still available, you may
> want to have a look at their output to help understand the C++ object
> model, though the generated C code may not be designed to be
> particularly readable, and they won't support later C++ additions,
> such as templates.

Comeau's current compiler does this.

--
John Carson

Re: C++ in ternms of C by Severian

Severian
Thu Apr 21 20:19:06 CDT 2005

On Fri, 22 Apr 2005 10:44:28 +1000, "John Carson"
<jcarson_n_o_sp_am_@netspace.net.au> wrote:

>"Severian [MVP]" <severian@chlamydia-is-not-a-flower.com> wrote in
>message news:gjrf61p3l5erbl9n8c5k58sa5lf3lqicr2@4ax.com
>>
>> Most of the original C++ compilers converted C++ to C, rather than
>> directly to machine code. If any of these are still available, you may
>> want to have a look at their output to help understand the C++ object
>> model, though the generated C code may not be designed to be
>> particularly readable, and they won't support later C++ additions,
>> such as templates.
>
>Comeau's current compiler does this.

Thanks, I didn't realize that.

--
Phillip Crews aka Severian
Microsoft MVP, Windows SDK
Posting email address is real, but please post replies on the newsgroup.

Re: C++ in ternms of C by ajk

ajk
Fri Apr 22 08:35:07 CDT 2005

On Thu, 21 Apr 2005 17:26:44 -0700, "Eugene Gershnik"
<gershnik@hotmail.com> wrote:

>That's one possibility. Another is
>
>[e][f][b][c][d]
>
>IIRC members are required to follow each other within a single
>public/private/protected block. The blocks themselves can be positioned in
>any order.
>Practically, I don't know of any compiler that makes use of this freedom.

Actually the initialization order is determined for C++ in the order
the member variables are declared. That is why some programs like
PC-LINT complain when the programmer doesn't initialize the variables
in the same order they are declared.
--
"I never forget a face, but in your case I'll be glad to make an exception."
Groucho Marx.

Re: C++ in ternms of C by comeau

comeau
Fri Apr 22 09:00:54 CDT 2005

In article <DeltaOne.1ntz5w@mail.codecomments.com>,
DeltaOne <DeltaOne.1ntz5w@mail.codecomments.com> wrote:
>Hi, I am planning to study how we can implement things that we implement
>in c++ in c and using a bit asm also. First thing i want to know is
>about class and struct difference. How is the private and public part
>implemented in the c++ exactly or how is the internal representation
>done. I tried to analise the ASM file produ ced my the VC++ compil er.
>But there i wrote the following code class t{ private: __int8 i;
>public: void valF(); }; int main(){ t dat; t dat1; t p; dat.valF();
>p.valF(); dat1. valF(); return 1; } void t::v alF(){ i=3; return ; } in
>the above class "t" i changed the specif ier of "i" from private to
>public. but in both cases th e ASM code generated was same. Even the
>exe file was same.Then how in the ru n time it knows which data is
>private and which data is public. Is is implem ented by the runtime
>libraries? or how? is there any site or book from which i can ge t more
>info on it? Please let me know this first case.Hos can i im plement this
>private and public thing in C and if required some ASM inline a lso. I
>want to use a pure C compiler for this not a C++ compiler.How is it r
>epresented by the c++ compiler in translation to intermediate stage.

Check out Lippman's Inside the C++ Object Model.
Details on it can be found at http://www.comeaucomputing.com/booklist

Generally speaking, the issue of C++ to C translation is not
trivial. In fact it is grossly complicated. Even if you are
trying to set up a higher level coding stylesheet or something
for this, mimicing things too deeply may not be the best approach.

That said, on the issue above, note that access specifiers
such as private are protection against coding accidents,
and not against fraud or security per se. Therefore,
at runtime, a C like struct in C++ is going to usually
look exactly that same as the same struct in C. Of course,
things complicate because C++ also have extensions and
differences over C, initialization and ordering issues, etc.
But if you talking about POD structs and only at the simplest
levels, the similarity is there.

Lastly, you ask about how it is representing by the C++ compiler
in the intermediate stage. It is of course at that point entered
into the respective tables with their respective characterstics.
The emitted output code, of whatever form, then needs to pull
from that info to determine what is what. In a normal POD struct,
there normally isn't anything else additional going on that the
compiler needs to consider over what a C compiler needs to consider.
As one move from POD struct to non-POD structs, they sky begins
to become the limit given all the possibilities, complexities, etc.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

Re: C++ in ternms of C by comeau

comeau
Fri Apr 22 09:03:37 CDT 2005

In article <d47lrp$ssf$1@ns2.fe.internet.bosch.com>,
Eberhard Schefold <eberhard.schefold@de.bosch.com> wrote:
>DeltaOne schrieb/wrote:
>
>> Then how in the ru n time it knows which data is
>> private and which data is public.
>
>There is no case where the executable needs to know whether a member is
>private or public. That distinction can and must be made at compile time.

Most of the benefit of access specified is usually at compile time,
however, it is allowed to have impacts on the generated code.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

Re: C++ in ternms of C by comeau

comeau
Fri Apr 22 09:10:06 CDT 2005

In article <uRjypwpRFHA.2604@TK2MSFTNGP10.phx.gbl>,
Mark Randall <markyr@REMOVETHISgoogle.ANDTHIScom> wrote:
>A class and a structure are effectivly the same in terms of code once
>compiled.
>
>A class has its member variables,
>
>Class A
>{
>public:
> int b, c, d;
>private:
> double e, f;
>};
>
>struct tagA
>{
> int b, c, d;
> double e, f;
>};
>
>
>Each of these is represented in memory as
>
>Class [b][c][d][ e ][ f ]
>Struct [b][c][d][ e ][ f ]

No. tagA is require to be represented as you show (noting that
info on say padding is allowed to be added differently), but
the requirement for A is not constrained to just one the
you showed. For instance, it can also be:

[e][f][b][c][d]

>To consider the other aspects of OOP, we obviously have public, private and
>protected; these are to cause code to be more secure, prevent the fiddling
>by other classes and to impliment a much more powerful and descriptive
>structure to a class. These are of course, completle nonsense to the linker,

Actually, they are allowed to have meaning to the "linker" (whatever
that is), just that they don't in many implementations.

>the compiler performs these checks to tell us that our code conforms to the
>design specification of the class (for example, not changing the member
>variable 'int m_Count' directly when we should have to call the public 'int
>IncrementCount( )'.
>
>You can consider though, when exporting DLL's and functions, the linker will
>utilise these to know which to add to the exports table and which not to.
>
>There is also the consideration of virtual functions, for these the calling
>function needs to know which of the class methods (which in assembly code
>are all accessable anyway) to call, for this we need a special lookup
>table - this is stored elsewhere in the programs data for each individual
>class (not instance of the class).

Right so C++ is allowed to add undeclared members to some classes
in addition to issues of padding, etc.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

Re: C++ in ternms of C by comeau

comeau
Fri Apr 22 09:12:20 CDT 2005

In article <gjrf61p3l5erbl9n8c5k58sa5lf3lqicr2@4ax.com>,
Severian [MVP] <severian@chlamydia-is-not-a-flower.com> wrote:
>Most of the original C++ compilers converted C++ to C, rather than
>directly to machine code. If any of these are still available, you may
>want to have a look at their output to help understand the C++ object
>model, though the generated C code may not be designed to be
>particularly readable, and they won't support later C++ additions,
>such as templates.

Comeau C++ is currently the most compliant compiler available,
so it supports all later C++ additions, and usually it is sold
to generate C as its object code, hence C++ to C, but strictly
as an implementation detail only. It would not be handy for
anything except what we speficically code it for (a specific
CPU, OS, and C compiler that is), and would be hard pressed
to use it as a teaching aide even if that were not the case.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

Re: C++ in ternms of C by comeau

comeau
Fri Apr 22 09:13:29 CDT 2005

In article <kqjg61l9qi7ogsdbr2n8m2g7uktsnf8502@4ax.com>,
Severian [MVP] <severian@chlamydia-is-not-a-flower.com> wrote:
>On Fri, 22 Apr 2005 10:44:28 +1000, "John Carson"
><jcarson_n_o_sp_am_@netspace.net.au> wrote:
>
>>"Severian [MVP]" <severian@chlamydia-is-not-a-flower.com> wrote in
>>message news:gjrf61p3l5erbl9n8c5k58sa5lf3lqicr2@4ax.com
>>>
>>> Most of the original C++ compilers converted C++ to C, rather than
>>> directly to machine code. If any of these are still available, you may
>>> want to have a look at their output to help understand the C++ object
>>> model, though the generated C code may not be designed to be
>>> particularly readable, and they won't support later C++ additions,
>>> such as templates.
>>
>>Comeau's current compiler does this.
>
>Thanks, I didn't realize that.

I am qualified to verify this :) As in my other post, this is
normally not something users need to get involved in/with though
and so should be considered an implementation detail only.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?

Re: C++ in ternms of C by comeau

comeau
Fri Apr 22 09:17:03 CDT 2005

In article <v5vh611m9hcuulvgfiiusnls3qvg3kqi1n@4ax.com>,
ajk <gandalf<at> wrote:
>On Thu, 21 Apr 2005 17:26:44 -0700, "Eugene Gershnik"
><gershnik@hotmail.com> wrote:
>
>>That's one possibility. Another is
>>
>>[e][f][b][c][d]
>>
>>IIRC members are required to follow each other within a single
>>public/private/protected block. The blocks themselves can be positioned in
>>any order.
>>Practically, I don't know of any compiler that makes use of this freedom.
>
>Actually the initialization order is determined for C++ in the order
>the member variables are declared.

And yet in memory, members may be laid out differently than
presented in source code; as Eugene mentioned, they may be shifter
between access specific categories, even if there are multiple ones,
so for instance this:

struct xyz {
private: int a1;
private: int a2;
private: int a3;
};

means in memory it does not have to be a1 a2 a3, in the above
example (other example will differ!) it can also be
a2 a3 a1 and a2 a1 a3 and a3 a1 a2 and a3 a2 a1.

> That is why some programs like
>PC-LINT complain when the programmer doesn't initialize the variables
>in the same order they are declared.

Related but different issue.
--
Greg Comeau / Comeau for the Mac? Stay tuned.
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?