The value returned is an unsigned integral value of type size_t with the amount of bytes between the specified member and the beginning of its structure.
Because of the extended functionality of structs in C++, in this language, the use of offsetof is restricted to "POD types", which for classes, more or less corresponds to the C concept of struct (although non-derived classes with only public non-virtual member functions and with no constructor and/or destructor would also qualify as POD).
Parameters
- type
- A class type in which member is a valid member designator.
- member
- A member designator of class type.
Return value
A value of type size_t with the offset value of member in type.Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Output:
offsetof(mystruct,singlechar) is 0 offsetof(mystruct,arraymember) is 1 offsetof(mystruct,anotherchar) is 11 |
