4 * @author Sebastian Hack
8 * Copyright (C) 2005 Universitaet Karlsruhe
9 * Released under the GPL
16 * Get the offset of a member of a struct.
17 * @param type The type of the struct member is in.
18 * @param member The name of the member.
19 * @return The offset of member in type in bytes.
21 #define offset_of(type, member) \
22 ((char *) &(((type *) 0)->member) - (char *) 0)
25 * Make pointer to the struct from a pointer to a member of that struct.
26 * @param ptr The pointer to the member.
27 * @param type The type of the struct.
28 * @param member The name of the member.
29 * @return A pointer to the struct member is in.
31 #define container_of(ptr, type, member) \
32 ((type *) ((char *) (ptr) - offset_of(type, member)))
35 * Get the number of elements of a static array.
36 * @param arr The static array.
37 * @return The number of elements in that array.
39 #define array_size(arr) \
40 (sizeof(arr) / sizeof((arr)[0]))