offsetof
offsetof (type,member)
Return member offset
This macro with functional form returns the offset value in bytes of member
member in the data structure or union type
type.
The value returned is an unsigned integral value of type size_t with the number of bytes between the specified member and the beginning of its structure.
Parameters
-
type
-
A type in which
member is a valid member designator.
type shall be a structure or union type.
type shall be a POD class (including unions).
type shall be a standard-layout class (including unions).
member
- A member of type.
Return value
A value of type size_t with the offset value of member in type.
Example
| |
Output:
offsetof(struct foo,a) is 0 offsetof(struct foo,b) is 1 offsetof(struct foo,c) is 11 |
转自 http://www.cplusplus.com/reference/cstddef/offsetof/