Print this page
3373 gcc >= 4.5 concerns about offsetof()


 353 #define DECL_BITFIELD3(_a, _b, _c)                      \
 354         uint8_t _c, _b, _a
 355 #define DECL_BITFIELD4(_a, _b, _c, _d)                  \
 356         uint8_t _d, _c, _b, _a
 357 #define DECL_BITFIELD5(_a, _b, _c, _d, _e)              \
 358         uint8_t _e, _d, _c, _b, _a
 359 #define DECL_BITFIELD6(_a, _b, _c, _d, _e, _f)          \
 360         uint8_t _f, _e, _d, _c, _b, _a
 361 #define DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g)      \
 362         uint8_t _g, _f, _e, _d, _c, _b, _a
 363 #define DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h)  \
 364         uint8_t _h, _g, _f, _e, _d, _c, _b, _a
 365 #else
 366 #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
 367 #endif  /* _BIT_FIELDS_LTOH */
 368 
 369 /* avoid any possibility of clashing with <stddef.h> version */
 370 #if defined(_KERNEL) && !defined(_KMEMUSER)
 371 
 372 #if !defined(offsetof)



 373 #define offsetof(s, m)  ((size_t)(&(((s *)0)->m)))

 374 #endif /* !offsetof */
 375 
 376 #define container_of(m, s, name)                        \
 377         (void *)((uintptr_t)(m) - (uintptr_t)offsetof(s, name))
 378 
 379 #define ARRAY_SIZE(x)   (sizeof (x) / sizeof (x[0]))
 380 #endif /* _KERNEL, !_KMEMUSER */
 381 
 382 #ifdef  __cplusplus
 383 }
 384 #endif
 385 
 386 #endif  /* _SYS_SYSMACROS_H */


 353 #define DECL_BITFIELD3(_a, _b, _c)                      \
 354         uint8_t _c, _b, _a
 355 #define DECL_BITFIELD4(_a, _b, _c, _d)                  \
 356         uint8_t _d, _c, _b, _a
 357 #define DECL_BITFIELD5(_a, _b, _c, _d, _e)              \
 358         uint8_t _e, _d, _c, _b, _a
 359 #define DECL_BITFIELD6(_a, _b, _c, _d, _e, _f)          \
 360         uint8_t _f, _e, _d, _c, _b, _a
 361 #define DECL_BITFIELD7(_a, _b, _c, _d, _e, _f, _g)      \
 362         uint8_t _g, _f, _e, _d, _c, _b, _a
 363 #define DECL_BITFIELD8(_a, _b, _c, _d, _e, _f, _g, _h)  \
 364         uint8_t _h, _g, _f, _e, _d, _c, _b, _a
 365 #else
 366 #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
 367 #endif  /* _BIT_FIELDS_LTOH */
 368 
 369 /* avoid any possibility of clashing with <stddef.h> version */
 370 #if defined(_KERNEL) && !defined(_KMEMUSER)
 371 
 372 #if !defined(offsetof)
 373 #if defined(__GNUC__)
 374 #define offsetof(s, m)  __builtin_offsetof(s, m)
 375 #else
 376 #define offsetof(s, m)  ((size_t)(&(((s *)0)->m)))
 377 #endif
 378 #endif /* !offsetof */
 379 
 380 #define container_of(m, s, name)                        \
 381         (void *)((uintptr_t)(m) - (uintptr_t)offsetof(s, name))
 382 
 383 #define ARRAY_SIZE(x)   (sizeof (x) / sizeof (x[0]))
 384 #endif /* _KERNEL, !_KMEMUSER */
 385 
 386 #ifdef  __cplusplus
 387 }
 388 #endif
 389 
 390 #endif  /* _SYS_SYSMACROS_H */