]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Add static_assert_array_size()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Sat, 3 Dec 2022 11:46:02 +0000 (13:46 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 12 Dec 2022 09:49:39 +0000 (11:49 +0200)
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

index 13e41d855ffa7b1f73c7fae275cfdf07ef0b47de..2b1ecde41df6adef70dbe354b7d0676c189993ed 100644 (file)
@@ -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;