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?

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top