這個錯誤有點鬧心,因爲 C++11 把 關鍵字typeof改爲decltype了。
怎麼做好兩者的兼容性呢,只能使用 if 宏判斷來做,比如我的代碼:
#if __cplusplus >= 201103L
#define container_of(ptr, type, member) ({ \
const decltype(((type *)0)->member)*__mptr = (ptr); \
(type *)((char *)__mptr - offsetof_lh(type, member)); })
#else
#define container_of(ptr, type, member) ({ \
const typeof(((type *)0)->member)*__mptr = (ptr); \
(type *)((char *)__mptr - offsetof_lh(type, member)); })
#endif
參考: