vppinfra: add FOREACH_ARRAY_ELT macro 08/38508/2
authorDamjan Marion <damarion@cisco.com>
Thu, 16 Mar 2023 16:34:30 +0000 (16:34 +0000)
committerFlorin Coras <florin.coras@gmail.com>
Fri, 17 Mar 2023 16:20:02 +0000 (16:20 +0000)
Type: improvement
Change-Id: Iac1b3a66176c9a38a161246159140f30a1c168da
Signed-off-by: Damjan Marion <damarion@cisco.com>
.clang-format
src/vppinfra/clib.h

index 8326a07..1471d0f 100644 (file)
@@ -20,6 +20,7 @@ ForEachMacros:
   - 'vlib_foreach_rx_tx'
   - 'foreach_vlib_main'
   - 'foreach_set_bit_index'
+  - 'FOREACH_ARRAY_ELT'
   - 'RTE_ETH_FOREACH_DEV'
 
 StatementMacros:
index 8d1e412..7a8029a 100644 (file)
@@ -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)