misc: add type-safe "offsetof"
This uses the GCC extension "typeof" to implement a type-safe "offsetof" similar to the implementation in the linux kernel. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This commit is contained in:
parent
68633aee06
commit
7a7f977d43
@ -34,6 +34,14 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* miscellaneous */
|
||||
|
||||
#define kmscon_offsetof(pointer, type, member) ({ \
|
||||
const typeof(((type*)0)->member) *__ptr = (pointer); \
|
||||
(type*)(((char*)__ptr) - offsetof(type, member)); \
|
||||
})
|
||||
|
||||
/* ring buffer for arbitrary byte-streams */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user