From d24c2b6b71873d6bde25eecfede9d34102eaa192 Mon Sep 17 00:00:00 2001 From: Jamie McCrae Date: Thu, 1 Sep 2022 15:27:39 +0100 Subject: [PATCH] sys: util: Prevent ARRAY_SIZE being defined if already defined Prevents ARRAY_SIZE being defined by util.h if it is already defined, prevents possible future include file ordering issues that have plagued CI tests in the past. Signed-off-by: Jamie McCrae --- include/zephyr/sys/util.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/zephyr/sys/util.h b/include/zephyr/sys/util.h index 17adfcef4ac22..5b5c2488c93d4 100644 --- a/include/zephyr/sys/util.h +++ b/include/zephyr/sys/util.h @@ -82,7 +82,9 @@ extern "C" { /* The built-in function used below for type checking in C is not * supported by GNU C++. */ +#ifndef ARRAY_SIZE #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) +#endif #else /* __cplusplus */ @@ -105,8 +107,10 @@ extern "C" { * * In C, passing a pointer as @p array causes a compile error. */ +#ifndef ARRAY_SIZE #define ARRAY_SIZE(array) \ ((size_t) (IS_ARRAY(array) + (sizeof(array) / sizeof((array)[0])))) +#endif #endif /* __cplusplus */