mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
core/include/kernel_defines.h: Fix container_of()
container_of() is safe to use in regard to alignment requirements, when used correctly. Using `uintptr_t` instead of `char *` for applying the offset results in -Wcast-align not complaining.
This commit is contained in:
parent
f3a5ee69e0
commit
85e506e893
@ -22,6 +22,7 @@
|
||||
#define KERNEL_DEFINES_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -47,15 +48,15 @@ extern "C" {
|
||||
# define container_of(PTR, TYPE, MEMBER) \
|
||||
(_Generic((PTR), \
|
||||
const __typeof__ (((TYPE *) 0)->MEMBER) *: \
|
||||
((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))), \
|
||||
((TYPE *) ((uintptr_t) (PTR) - offsetof(TYPE, MEMBER))), \
|
||||
__typeof__ (((TYPE *) 0)->MEMBER) *: \
|
||||
((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) \
|
||||
((TYPE *) ((uintptr_t) (PTR) - offsetof(TYPE, MEMBER))) \
|
||||
))
|
||||
#elif defined __GNUC__
|
||||
# define container_of(PTR, TYPE, MEMBER) \
|
||||
(__extension__ ({ \
|
||||
__extension__ const __typeof__ (((TYPE *) 0)->MEMBER) *__m____ = (PTR); \
|
||||
((TYPE *) ((char *) __m____ - offsetof(TYPE, MEMBER))); \
|
||||
((TYPE *) ((uintptr_t) __m____ - offsetof(TYPE, MEMBER))); \
|
||||
}))
|
||||
#else
|
||||
# define container_of(PTR, TYPE, MEMBER) \
|
||||
|
Loading…
Reference in New Issue
Block a user