C examples for stddef.h:offsetof
macro
<cstddef>
offsetof (type,member)
returns the offset value in bytes of member member in the data structure or union type type.
Parameter | Description |
---|---|
type | A type in which member is a valid member designator. |
member | A member of type. |
A value of type size_t with the offset value of member in type.
#include <stdio.h> #include <stddef.h> struct foo {/*from w ww . ja v a2 s .c o m*/ char a; char b[10]; char d[10]; int i[1000]; char c; }; int main () { printf ("offsetof(struct foo,a) is %d\n",(int)offsetof(struct foo,a)); printf ("offsetof(struct foo,b) is %d\n",(int)offsetof(struct foo,b)); printf ("offsetof(struct foo,c) is %d\n",(int)offsetof(struct foo,c)); return 0; }