1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-15 20:35:33 +03:00

improve container_of macro

This commit is contained in:
Petr Ledvina 2015-10-09 11:20:36 +02:00 committed by Dominic Clifton
parent dc5a888633
commit 48cdf650d9

View file

@ -42,9 +42,9 @@ http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html
#else #else
// non ISO variant from linux kernel; checks ptr type, but triggers 'ISO C forbids braced-groups within expressions [-Wpedantic]' // non ISO variant from linux kernel; checks ptr type, but triggers 'ISO C forbids braced-groups within expressions [-Wpedantic]'
// __extension__ is here to disable this warning // __extension__ is here to disable this warning
#define container_of(ptr, type, member) __extension__ ({ \ #define container_of(ptr, type, member) ( __extension__ ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );}) (type *)( (char *)__mptr - offsetof(type,member) );}))
static inline int16_t cmp16(uint16_t a, uint16_t b) { return a-b; } static inline int16_t cmp16(uint16_t a, uint16_t b) { return a-b; }
static inline int32_t cmp32(uint32_t a, uint32_t b) { return a-b; } static inline int32_t cmp32(uint32_t a, uint32_t b) { return a-b; }