diff mbox series

[RFC,v1,3/5] lib: Add `sizeof_field()` macro

Message ID 20220606061209.335709-4-ammarfaizi2@gnuweeb.org (mailing list archive)
State New
Headers show
Series Ensure io_uring data structure consistentcy in liburing | expand

Commit Message

Ammar Faizi June 6, 2022, 6:12 a.m. UTC
The first use case of this macro is for data structure assertion at
compile time. It's like what we do in the io_uring.c in the kernel.

Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>
---
 src/lib.h | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/src/lib.h b/src/lib.h
index 40e2817..0db7499 100644
--- a/src/lib.h
+++ b/src/lib.h
@@ -26,6 +26,10 @@ 
 #define BUILD_BUG_ON(EXPR) static_assert(!(EXPR), "!(" #EXPR ") failed")
 #endif
 
+#ifndef sizeof_field
+#define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+#endif
+
 #ifndef offsetof
 #define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
 #endif