diff --git a/include/ucore/utils.h b/include/ucore/utils.h index 9adb19f..9d1e86c 100644 --- a/include/ucore/utils.h +++ b/include/ucore/utils.h @@ -48,7 +48,12 @@ //struct foo *f = CONTAINER_OF(p, struct foo, zap); #define CONTAINER_OF(ptr, type, member) ({ \ typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (void *)__mptr - offsetof(type, member) ); }) + (type *)( (unsigned char *)__mptr - offsetof(type, member) ); }) + +//Same as CONTAINER_OF, but for a const pointer to avoid gcc warnings.. +#define CONST_CONTAINER_OF(ptr, type, member) ({ \ +const typeof( ((const type *)0)->member ) *__mptr = (ptr); \ + (const type *)( (const unsigned char *)__mptr - offsetof(const type, member) ); }) /** Align a value. * @param val value to align