문제

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