This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: invalid offsetof from non-POD type


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 at codesourcery dot com : http://www.cs.bris.ac.uk/~nathan/ : nathan at acm dot org



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]