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 <damarion@cisco.com>
This commit is contained in:
@ -20,6 +20,7 @@ ForEachMacros:
|
||||
- 'vec_foreach_index_backwards'
|
||||
- 'vec_foreach_pointer'
|
||||
- 'vlib_foreach_rx_tx'
|
||||
- 'foreach_int'
|
||||
- 'foreach_vlib_main'
|
||||
- 'foreach_set_bit_index'
|
||||
- 'foreach_vlib_frame_bitmap_set_bit_index'
|
||||
|
@ -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 */
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user