|
ssm
0.0.2
Runtime Library for the Sparse Synchronous Model
|
A collection of helpful definitions which are not specific to SSM. More...
A collection of helpful definitions which are not specific to SSM.
Macros | |
| #define | member_type(type, member) __typeof__(((type *)0)->member) |
| Obtain the type of a struct member. More... | |
| #define | container_of(ptr, type, member) |
| Obtain the pointer to an outer, enclosing struct. More... | |
| #define member_type | ( | type, | |
| member | |||
| ) | __typeof__(((type *)0)->member) |
Obtain the type of a struct member.
Intended for use in container_of, for type safety.
When GNU C is not available, falls back to ISO C99 and returns const void (see https://stackoverflow.com/a/10269925/10497710).
For instance, given the following struct definition:
member_type(struct foo, baz) expands to float.
| type | the struct type. |
| member | the name of the member in type. |
| #define container_of | ( | ptr, | |
| type, | |||
| member | |||
| ) |
Obtain the pointer to an outer, enclosing struct.
For example, with the following struct definition:
Given some float *p, container_of(p, struct foo, baz) will return a pointer to the enclosing struct foo. The caller is responsible for ensuring that such an enclosing pointer actually exists.
Use this macro instead of pointer casting or pointer arithmetic; this macro is more principled in what it does and, with GNU C support, will trigger compiler warnings when ptr and the member type do not agree.
Adapted from the Linux kernel source (see https://stackoverflow.com/a/10269925/10497710).
| ptr | pointer to member. |
| type | type of enclosing struct. |
| member | name of member in enclosing struct. |