invalid offsetof from non-POD type

Gabriel Dos Reis gdr@integrable-solutions.net
Tue Apr 22 06:32:00 GMT 2003


Zack Weinberg <zack@codesourcery.com> writes:

| Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
| 
| > John Quigley <johnw@lowestplane.org> writes:
| >
| > | While it is not standards compliant code, gcc still provides the correct 
| > | result. 
| >
| > The key issue is what do you define to be the "correct" result when you
| > apply offsetof() to a non-POD?  
| 
| I have never really understood why the C++ standard imposes this
| restriction.  There would seem to be a well-defined answer to the
| question posed by offsetof(non-POD, data-member), since the data
| member does exist in memory at a well-defined offset from the
| beginning of the object.  If that weren't true the compiler wouldn't
| be able to generate accesses to it.

That statement is confused.  
The issue isn't that the compiler couldn't return some random number. 
And no, the data do not always exist in memory, for example, a
subobject of "empty" class type" does not always occupy memory. Let
alone, subobject of morally virtual base classes.  Which begs my
question.

-- Gaby



More information about the Gcc mailing list