From: Alejandro Colomar Date: Sun, 18 Feb 2024 17:32:31 +0000 (+0100) Subject: lib/sizeof.h: memberof(): Add macro X-Git-Tag: 4.15.0-rc3~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=544709fad3b2dd05f22414c1b70be53e6a3504f1;p=thirdparty%2Fshadow.git 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 Signed-off-by: Alejandro Colomar --- diff --git a/lib/sizeof.h b/lib/sizeof.h index f16e1a7bf..6847068ea 100644 --- a/lib/sizeof.h +++ b/lib/sizeof.h @@ -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