offsetof
From cppreference.com
Defined in header <cstddef>
|
||
#define offsetof(type, member) /*implementation-defined*/ |
||
The macro offsetof expands to a constant of type std::size_t, the value of which is the offset, in bytes, from the beginning of an object of specified type to its specified member, including padding if any.
Contents |
[edit] Notes
If type is not a standard-layout type, the behavior is undefined.
If member is a static member or a function member, the behavior is undefined.
The offset of the first member of a standard-layout type is always zero.
[edit] Exceptions
[edit] Possible implementation
#define offsetof(type,member) ((std::size_t) &(((type*)0)->member)) |
[edit] Example
Output:
the first element is at offset 0 the double is at offset 8
[edit] See also
unsigned integer type returned by the sizeof operator (typedef) | |
(C++11) |
checks if a type is standard-layout type (class template) |