Minor macro refactor

This commit is contained in:
Felix Kopp 2020-10-14 11:47:42 +00:00
parent fd4f87d595
commit 32afd10e99
No known key found for this signature in database
GPG key ID: C478BA0A85F75728
2 changed files with 11 additions and 1 deletions

View file

@ -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>
*

View file

@ -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)