[英]is a pointer to data member its offset?
我可以安全地假设数据成员的偏移量( offsetof(mystruct, myfield)
)在数值上等于使用&mystruct::myfield
检索的成员指针的原始值,还是它取决于实现?
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, ie the same thing that offsetof
evaluates to. 是的,是的,在现实生活中,最常见的指针指向数据成员指针的实现是(或基于)计划和简单偏移量,即offsetof
求值的对象相同。
Some implementations use the exact offset, resorting to 0xFFF...
pattern to represent the null-pointer value. 一些实现使用精确的偏移量,诉诸于0xFFF...
模式来表示空指针值。 Some implementatiuons reserve 0x000...
pattern for null-pointer value, while incrementing all "non-null" offsets by 1
. 一些实现为空指针值保留0x000...
模式,同时将所有“非空”偏移量增加1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.