lib/sizeof.h: memberof(): Add macro
This macro is useful to get the size of a member of a structure without having a variable of that type. Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
+5
-4
@@ -15,10 +15,11 @@
|
||||
#include "must_be.h"
|
||||
|
||||
|
||||
#define WIDTHOF(x) (sizeof(x) * CHAR_BIT)
|
||||
#define SIZEOF_ARRAY(a) (sizeof(a) + must_be_array(a))
|
||||
#define NITEMS(a) (SIZEOF_ARRAY((a)) / sizeof((a)[0]))
|
||||
#define STRLEN(s) (NITEMS(s) - 1)
|
||||
#define memberof(T, member) ((T){}.member)
|
||||
#define WIDTHOF(x) (sizeof(x) * CHAR_BIT)
|
||||
#define SIZEOF_ARRAY(a) (sizeof(a) + must_be_array(a))
|
||||
#define NITEMS(a) (SIZEOF_ARRAY((a)) / sizeof((a)[0]))
|
||||
#define STRLEN(s) (NITEMS(s) - 1)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
Reference in New Issue
Block a user