c++member-pointersoffsetof

is a pointer to data member its offset?


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?


Solution

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