Question

Am I safe to assume that the offset of a data member (offsetof(mystruct, myfield)) is numerically equal to the raw value of a member pointer retrieved with &mystruct::myfield, or is it implementation dependent?

Was it helpful?

Solution

No; the implementation of a pointer-to-member is not specified, and there is no defined conversion to get the "raw" value.

OTHER TIPS

Formally, it is implementation-dependent, of course. In real life, yes, the most popular implementation of pointer-to-data-member pointers is (or is based on) plan-and-simple offset, i.e. the same thing that offsetof evaluates to.

Some implementations use the exact offset, resorting to 0xFFF... pattern to represent the null-pointer value. Some implementatiuons reserve 0x000... pattern for null-pointer value, while incrementing all "non-null" offsets by 1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top