1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2025-10-02 23:13:56 -04:00

Add macro KERNAUX_CONTAINER_OF (#100)

* Add macro KERNAUX_CONTAINER_OF
* Add includes
* Add "examples/macro_container_of"
This commit is contained in:
Alex Kotov 2022-06-27 14:08:32 +03:00 committed by GitHub
parent f5ae8400c0
commit febd43c987
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 4 deletions

View file

@ -5,6 +5,12 @@
extern "C" {
#endif
#include <stddef.h>
#include <stdint.h>
#define KERNAUX_CONTAINER_OF(ptr, type, member) \
((type*)((uintptr_t)(ptr) - offsetof(type, member)))
#ifdef KERNAUX_ACCESS_PRIVATE
# define KERNAUX_PRIVATE_FIELD(id) id
# define KERNAUX_PROTECTED_FIELD(id) id