offsetof

From Wikipedia, the free encyclopedia

C's offsetof() macro is an ANSI C library feature found in stddef.h. It evaluates to the offset (in bytes) of a given member within a struct or union type, an expression of type size_t.

The offsetof() macro takes two parameters, the first being a structure name, and the second being the name of a member within the structure.

A typical implementation of the macro is:

#define offsetof(st, m)   ( (char *)&((st *)(0))->m - (char *)&((st *)(0)) )