summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2023-03-16 16:34:30 +0000
committerFlorin Coras <florin.coras@gmail.com>2023-03-17 16:20:02 +0000
commitf8b61fb538046e287063864349d43e98b62b5faf (patch)
tree6594d34abb0f82aab65410101ee0472da907d079
parentf39485ff6aa112c8ddcac06c99911c406f0a36df (diff)
vppinfra: add FOREACH_ARRAY_ELT macro
Type: improvement Change-Id: Iac1b3a66176c9a38a161246159140f30a1c168da Signed-off-by: Damjan Marion <damarion@cisco.com>
-rw-r--r--.clang-format1
-rw-r--r--src/vppinfra/clib.h2
2 files changed, 3 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format
index 8326a07251b..1471d0f469b 100644
--- a/.clang-format
+++ b/.clang-format
@@ -20,6 +20,7 @@ ForEachMacros:
- 'vlib_foreach_rx_tx'
- 'foreach_vlib_main'
- 'foreach_set_bit_index'
+ - 'FOREACH_ARRAY_ELT'
- 'RTE_ETH_FOREACH_DEV'
StatementMacros:
diff --git a/src/vppinfra/clib.h b/src/vppinfra/clib.h
index 8d1e412db62..7a8029a30bd 100644
--- a/src/vppinfra/clib.h
+++ b/src/vppinfra/clib.h
@@ -74,6 +74,8 @@
#define BITS(x) (8*sizeof(x))
#define ARRAY_LEN(x) (sizeof (x)/sizeof (x[0]))
+#define FOREACH_ARRAY_ELT(a, b) \
+ for (typeof ((b)[0]) *(a) = (b); (a) - (b) < ARRAY_LEN (b); (a)++)
#define _STRUCT_FIELD(t,f) (((t *) 0)->f)
#define STRUCT_OFFSET_OF(t,f) offsetof(t, f)