This macro abstracts calculating how many items there are in an array.
Since recent versions of GCC and Clang provide a warning if we pass a
pointer to the construct in this macro, it is safe to use without any
further checks that the argument is an array.
Link: https://stackoverflow.com/a/57537491
Cc: Andrew Clayton <a.clayton@nginx.com>
Cc: Zhidao Hong <z.hong@f5.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
---
src/core/ngx_core.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 7ecdca0c..bbca2df2 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -102,6 +102,9 @@ typedef void (*ngx_connection_handler_pt)(ngx_connection_t *c);
#define ngx_max(val1, val2) ((val1 < val2) ? (val2) : (val1))
#define ngx_min(val1, val2) ((val1 > val2) ? (val2) : (val1))
+#define ngx_nitems(arr) (sizeof((arr)) / sizeof((arr)[0]))
+
+
void ngx_cpuinfo(void);
#if (NGX_HAVE_OPENAT)
--
2.37.2
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org