From: Daan De Meyer Date: Wed, 21 May 2025 08:47:56 +0000 (+0200) Subject: macro-fundamental: Introduce typeof_field() X-Git-Tag: v258-rc1~557^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=98ff8a198b6a3b3c3a40869ab744bcbcffb0b718;p=thirdparty%2Fsystemd.git macro-fundamental: Introduce typeof_field() --- diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index da5c0c9c503..6a75d7864a9 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -444,6 +444,7 @@ assert_cc(sizeof(dummy_t) == 0); #define DECLARE_SBAT(text) #endif +#define typeof_field(struct_type, member) typeof(((struct_type *) 0)->member) #define sizeof_field(struct_type, member) sizeof(((struct_type *) 0)->member) #define endoffsetof_field(struct_type, member) (offsetof(struct_type, member) + sizeof_field(struct_type, member)) #define voffsetof(v, member) offsetof(typeof(v), member) diff --git a/src/test/test-sizeof.c b/src/test/test-sizeof.c index fe90341dc81..9332f2750a3 100644 --- a/src/test/test-sizeof.c +++ b/src/test/test-sizeof.c @@ -65,7 +65,7 @@ int main(void) { check_no_sign(ino_t, SIZEOF_INO_T); check_no_sign(rlim_t, SIZEOF_RLIM_T); check(time_t, SIZEOF_TIME_T); - check(typeof(((struct timex *)0)->freq), SIZEOF_TIMEX_MEMBER); + check(typeof_field(struct timex, freq), SIZEOF_TIMEX_MEMBER); info_no_sign(typeof(function_pointer)); info_no_sign(void*);