From ad7e11fe21394b1862d65a54e1aec0828efcb2d8 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 3 Dec 2022 13:46:02 +0200 Subject: [PATCH] lib: Add static_assert_array_size() This is a simple way to make sure array size matches the given count, or give a compile time error if not. --- src/lib/lib.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/lib.h b/src/lib/lib.h index 13e41d855f..2b1ecde41d 100644 --- a/src/lib/lib.h +++ b/src/lib/lib.h @@ -63,6 +63,9 @@ typedef void lib_atexit_callback_t(void); #define LIB_ATEXIT_PRIORITY_DEFAULT 0 #define LIB_ATEXIT_PRIORITY_LOW 10 +#define static_assert_array_size(arr, count) \ + static_assert(N_ELEMENTS(arr) == (count), "array/enum size mismatch") + /* /dev/null opened as O_WRONLY. Opened at lib_init(), so it can be accessed also inside chroots. */ extern int dev_null_fd; -- 2.47.3