Minor macro refactor
This commit is contained in:
parent
fd4f87d595
commit
32afd10e99
2 changed files with 11 additions and 1 deletions
|
@ -16,6 +16,16 @@
|
|||
#define container_of(ptr, type, member) \
|
||||
( (type *)((void *)(ptr) - offsetof(type, member)) )
|
||||
|
||||
/**
|
||||
* Get the size of a struct member.
|
||||
*
|
||||
* @param type The type of the containing struct.
|
||||
* @param member The name of the member within the struct.
|
||||
* @return The size of the member in bytes.
|
||||
*/
|
||||
#define SIZEOF_MEMBER(type, member) \
|
||||
(sizeof( ((type *)0)->member ))
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>
|
||||
*
|
||||
|
|
|
@ -75,7 +75,7 @@ struct memblk {
|
|||
};
|
||||
|
||||
/** The length of the `size` member in `struct memblk`. */
|
||||
#define MEMBLK_SIZE_LENGTH (sizeof( typeof(((struct memblk *)0)->size) ))
|
||||
#define MEMBLK_SIZE_LENGTH SIZEOF_MEMBER(struct memblk, size)
|
||||
/** Total overhead per allocated block in bytes (2 * size_t). */
|
||||
#define MEMBLK_OVERHEAD (2 * MEMBLK_SIZE_LENGTH)
|
||||
|
||||
|
|
Loading…
Reference in a new issue