macro-fundamental: Introduce typeof_field()

This commit is contained in:
Daan De Meyer
2025-05-21 10:47:56 +02:00
parent e97cd0ca9f
commit 98ff8a198b
2 changed files with 2 additions and 1 deletions

View File

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

View File

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