c++ standard on class memory

Am I right in saying that the C++ standard defines what certain types of class must include (instance table pointer, virtual function table pointer, inherited members, etc) but does not define where about in memory of the class these will be stored when the class is instanced?

I.e. a computer could define a generic class structure as

class{
[inheritance pointer]
[virtual function pointer]
[base class contents]
class members (individually in any order the compiler wants)
}


And another compiler if it wished could define a generic class structure of

class {
[inheritance pointer]
[base class contents]
class members
[virtual function pointer]
}


EDIT: also is it valid for a compiler to add in any additional information into the class memory structure that might be used with custom language extensions?
Last edited on
What a compiler does with C++ code has nothing to do with the C++ standard, if I understand your question right. Change your optimization settings, and look at the assembly code, it will be different, depending on the optimization, and that is within the same compiler.

Different compilers will go different things just like GMC and Ford build their cars differently.

Much of this is up to the compiler.

Instance table? A table of all instances of the class? Maybe some compilers have them in debug mode, I don't know.

Most (all?) compilers use vtables but it doesn't have to be implemented like that. The standard doesn't say.

The standard say that non-static data members of a class with the same access control (public, private or protected) are allocated so that later members have higher addresses within the object. This does not mean the members have to be allocated next to each other, there could be padding or other things stored in between.

is it valid for a compiler to add in any additional information into the class memory structure that might be used with custom language extensions?

Yes.
Last edited on
I meant inheritance table, as in your base classes (don't know if I made that up but oh well)

Thanks for the info (now to get on with planning my extentions to C++ and a compiler =p )
Topic archived. No new replies allowed.