From: Timo Sirainen Date: Sat, 3 Dec 2022 11:46:02 +0000 (+0200) Subject: lib: Add static_assert_array_size() X-Git-Tag: 2.4.0~3296 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad7e11fe21394b1862d65a54e1aec0828efcb2d8;p=thirdparty%2Fdovecot%2Fcore.git 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. --- 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;