Inheritance and offsetof

J

James Kanze

On 24 Set, 09:40, James Kanze <[email protected]> wrote:

[...]
So, if I finally got it (and your explanations) straight, PODs
_have_ well defined, mandated layouts, while all other
user-defined classes/ structs have no mandated layout at all.

POD's don't have a defined layout either. All you're guaranteed
is that if there is no change of access between two *members*
(no guarantee what so ever for base classes) of a class, then
they will be layed out in the order they are declared. With
more or less padding between them.

In practice, of course, most systems define the layout of a C
struct as part of their system ABI, and any C++ implementation
will conform to this for POD's, and probably for all layout not
involving inheritance. Under Windows on a PC, or under Solaris
on a Sparc, for example, you know the layout of a POD. Not from
the C++ standard, of course, but from the system ABI
specification.
 
F

Francesco S. Carta

On 24 Set, 09:40, James Kanze <[email protected]> wrote:

    [...]
So, if I finally got it (and your explanations) straight, PODs
_have_ well defined, mandated layouts, while all other
user-defined classes/ structs have no mandated layout at all.

POD's don't have a defined layout either.  All you're guaranteed
is that if there is no change of access between two *members*
(no guarantee what so ever for base classes) of a class, then
they will be layed out in the order they are declared.  With
more or less padding between them.

In practice, of course, most systems define the layout of a C
struct as part of their system ABI, and any C++ implementation
will conform to this for POD's, and probably for all layout not
involving inheritance.  Under Windows on a PC, or under Solaris
on a Sparc, for example, you know the layout of a POD.  Not from
the C++ standard, of course, but from the system ABI
specification.

Ah, OK, now I understand better what all of those discussions were
about.

Thanks a lot, once more.

Have good time,
Francesco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top