macro: introduce FOREACH_ARRAY() macro

The pattern that runs all array element is quite common.
But, sometimes, the number of element may be in a signed integer, or the
array may be NULL.
This commit is contained in:
Yu Watanabe
2023-03-07 13:27:16 +09:00
parent 9200e520ad
commit 5716c27e1f
2 changed files with 57 additions and 0 deletions
+7
View File
@@ -297,6 +297,13 @@ static inline int __coverity_check_and_return__(int condition) {
p != (typeof(p)) POINTER_MAX; \
p = *(++_l))
#define _FOREACH_ARRAY(i, array, num, m, s) \
for (typeof(num) m = (num); m > 0; m = 0) \
for (typeof(array[0]) *s = (array), *i = s; s && i < s + m; i++)
#define FOREACH_ARRAY(i, array, num) \
_FOREACH_ARRAY(i, array, num, UNIQ_T(m, UNIQ), UNIQ_T(s, UNIQ))
#define DEFINE_TRIVIAL_DESTRUCTOR(name, type, func) \
static inline void name(type *p) { \
func(p); \