From 08057947f3da441d571420d4594ce1e3888516ea Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Fri, 29 Sep 2023 14:31:08 +0200 Subject: vppinfra: add foreach_int macro foreach_int(x, 1, 3, 5, 7) { fformat(stdout, "x is %u\n", x); } Type: improvement Change-Id: Idc355f4a284f421b150e3acb7a3a57bcede408c7 Signed-off-by: Damjan Marion --- src/vppinfra/types.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/vppinfra/types.h') diff --git a/src/vppinfra/types.h b/src/vppinfra/types.h index a3fbfcc845b..42217968dcc 100644 --- a/src/vppinfra/types.h +++ b/src/vppinfra/types.h @@ -196,6 +196,12 @@ typedef i64 i64u __attribute__ ((aligned (1), __may_alias__)); typedef word wordu __attribute__ ((aligned (1), __may_alias__)); typedef uword uwordu __attribute__ ((aligned (1), __may_alias__)); +#define foreach_int(__var, ...) \ + for (int __int_array[] = { __VA_ARGS__ }, *__int_ptr = __int_array, \ + __var = *__int_ptr; \ + __int_ptr - ARRAY_LEN (__int_array) < __int_array; \ + __var = *++__int_ptr) + #endif /* included_clib_types_h */ /* -- cgit 1.2.3-korg