You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
486 B
22 lines
486 B
4 years ago
|
#ifndef WFP_UTIL_CONTAINER_OF_H
|
||
|
#define WFP_UTIL_CONTAINER_OF_H
|
||
6 years ago
|
|
||
|
#ifndef __cplusplus
|
||
|
#include <stddef.h>
|
||
|
#else
|
||
|
#include <cstddef>
|
||
|
#endif
|
||
|
|
||
5 years ago
|
#ifdef __GNUC__
|
||
4 years ago
|
#define wfp_container_of(pointer, type, member) \
|
||
5 years ago
|
({ \
|
||
|
const typeof( ((type *)0)->member ) * __member = (pointer); \
|
||
|
(type *)( (char *)__member - offsetof(type, member) ); \
|
||
|
})
|
||
|
#else
|
||
4 years ago
|
#define wfp_container_of(pointer, type, member) \
|
||
6 years ago
|
(type *) (((char *) pointer) - offsetof(type, member))
|
||
5 years ago
|
#endif
|
||
6 years ago
|
|
||
|
#endif
|