Get rid of aligment warning on CONTAINER_OF in clang
This commit is contained in:
@@ -48,12 +48,14 @@
|
|||||||
//struct foo *f = CONTAINER_OF(p, struct foo, zap);
|
//struct foo *f = CONTAINER_OF(p, struct foo, zap);
|
||||||
#define CONTAINER_OF(ptr, type, member) ({ \
|
#define CONTAINER_OF(ptr, type, member) ({ \
|
||||||
typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||||
(type *)( (unsigned char *)__mptr - offsetof(type, member) ); })
|
(type *)((void *)(unsigned char *)__mptr - offsetof(type, member) ); })
|
||||||
|
|
||||||
|
//the void* cast is to suppress alignment warnings
|
||||||
|
|
||||||
//Same as CONTAINER_OF, but for a const pointer to avoid gcc warnings..
|
//Same as CONTAINER_OF, but for a const pointer to avoid gcc warnings..
|
||||||
#define CONST_CONTAINER_OF(ptr, type, member) ({ \
|
#define CONST_CONTAINER_OF(ptr, type, member) ({ \
|
||||||
const typeof( ((const type *)0)->member ) *__mptr = (ptr); \
|
const typeof( ((const type *)0)->member ) *__mptr = (ptr); \
|
||||||
(const type *)( (const unsigned char *)__mptr - offsetof(const type, member) ); })
|
(const type *)((const void *)(const unsigned char *)__mptr - offsetof(const type, member) ); })
|
||||||
|
|
||||||
/** Align a value.
|
/** Align a value.
|
||||||
* @param val value to align
|
* @param val value to align
|
||||||
|
|||||||
Reference in New Issue
Block a user