invalid offsetof from non-POD type

Nathan Sidwell nathan@codesourcery.com
Tue Apr 22 10:50:00 GMT 2003


Gabriel Dos Reis wrote:

> I'm not quibbling over the details: Actually the real semantics are in
> the detail.  How do you handle multiple and virtual inheritance?
The std already contains wording (wrt to base casting, IIRC), where you can
do something via a non-virtual base path that you cannot do via a virtual
base path. offsetof is the same.
1) empty members and bases are not a problem. They have an address/offset,
but you cannot touch the storage at that location.
2) multiple non-virtual inheritance is no more a problem than in other data
member access situations.

Like Zack, I think it strange that I can write &thing.member but not
offsetof(thing, member) (modulo virtual bases). I can even write
'(char *)&thing.member - (char *)&thing', and all sane compilers will
evaluate it at compile time.

It is interesting that John Quigley has a large body of real code
that relies on the more lenient interpretation - if there's a lot of
it out there, offsetof should be extended.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
          The voices in my head said this was stupid too
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org




More information about the Gcc mailing list