diff --git a/container_of.h b/container_of.h new file mode 100644 index 0000000000..b5e6d2070e --- /dev/null +++ b/container_of.h @@ -0,0 +1,26 @@ +#ifndef _CONTAINER_OF_H +#define _CONTAINER_OF_H + +#ifdef __cplusplus + +#include +#include + +extern "C" { + +#define container_of(ptr, type, member) ({ \ + auto const *__mptr = static_cast<__typeof__( ((type *)0)->member ) const*>(ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) +} + +#else // __cplusplus + +#include +#include + +#define container_of(ptr, type, member) ({ \ + const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) +#endif + +#endif // _CONTAINER_OF_H diff --git a/flist.h b/flist.h index 6c06f50155..39a9c3f1bf 100644 --- a/flist.h +++ b/flist.h @@ -4,17 +4,10 @@ #include #include -#ifdef __cplusplus +#include "container_of.h" +#ifdef __cplusplus extern "C" { - -#define container_of(ptr, type, member) ({ \ - auto const *__mptr = static_cast<__typeof__( ((type *)0)->member ) const*>(ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) -#else -#define container_of(ptr, type, member) ({ \ - const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) #endif /*