[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: Re: [linux-india-programmers] C++ question
> I really should not be seeing the value of var, right?
If you had
int a ;
X y ;
(int *) &y would actually give you &(y.a). A class is just a structure,
internally. Non-inlined functions are replaced by function pointers;
overloaded names are resolved using mangling; access to public and
private variables are handled using typing; there may be "hidden" members,
sometimes, as will happen in derived classes with virtual functions; a
derived class will turn out to be a larger structure than the class
definition would lead you to believe; but a class is essentially a structure.
So it all eventually depends on how the internal structure definition
is; if the declaration order is maintained and all generated members are
inserted after declared members, you'll see the behaviour you're seeing.
I don't think there are guarantees about that tho'.
It may be instructive to see the output of the AT&T C++ to C translator,
which was one of the early ways of programming with C++; it is a frontend
which converts all your C++ code to C code, and uses a C compiler along
with a library. If you can get hold of that, you can see how it handles
I guess the C++ ARM also has something about this; would anyone confirm?