From 90c2e3561c655c9485990e6032bcaa4abddfd767 Mon Sep 17 00:00:00 2001 From: Jeff Lucovsky Date: Sun, 17 Nov 2019 15:09:11 -0500 Subject: [PATCH] Add general purpose `ARRAY_SIZE` macro This commit adds `ARRAY_SIZE` as an helper for determining the number of elements in an initialized array. The calculation is the same but the macro provides a convenient shortcut. The implementation was borrowed from the kernel sources. --- src/suricata-common.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/suricata-common.h b/src/suricata-common.h index 627de0d78e..b55509c52e 100644 --- a/src/suricata-common.h +++ b/src/suricata-common.h @@ -494,5 +494,8 @@ char *strptime(const char * __restrict, const char * __restrict, struct tm * __r extern int coverage_unittests; extern int g_ut_modules; extern int g_ut_covered; + +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) + #endif /* __SURICATA_COMMON_H__ */ -- 2.47.3