OFFSETOF - offset of structure member.

(ANSI Standard)

Usage:

#include <stddef.h>
offset = offsetof(type,member);

Where:

type
refers to a structure type. This can be a name defined in a typedef statement, or it can have the form
struct TAG
member
refers to a member in the given structure type (see below). If this is a bit field, the behavior is undefined.
size_t offset;
is the byte offset of the given member in the structure type.

Description:

The "offsetof" macro expands to an expression giving the offset (in bytes) of a member of a structure type.

The "member" argument is typically the name of a member of the given type of structure. The precise technical requirements for member are these: if we were to declare a structure S with

static type S;

then the expression &(S.member) must evaluate to an address constant.

Examples:

size_t offset;
offset = offsetof(struct tm,tm_year);

Copyright © 1996, Thinkage Ltd.