Skip to content

Commit c5f3b12

Browse files
committed
LISTdo_n macro - make it possible to nest LISTdo's without -Wshadow warnings
1 parent adf5bf2 commit c5f3b12

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

include/express/linklist.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,19 @@ extern SC_EXPRESS_EXPORT struct freelist_head LIST_fl;
8989
#define LINKprev(link) (link)->prev
9090

9191
/** iteration */
92-
#define LISTdo(list, elt, type) \
93-
{struct Linked_List_ * __l = (list); \
94-
type elt; \
95-
Link __p; \
96-
if (__l) { \
97-
for (__p = __l->mark; (__p = __p->next) != __l->mark; ) { \
98-
(elt) = (type)((__p)->data);
92+
#define LISTdo(list, elt, type) LISTdo_n( list, elt, type, a )
93+
94+
/** LISTdo_n: LISTdo with nesting
95+
* parameter 'uniq' changes the variable names, allowing us to nest it without -Wshadow warnings
96+
*/
97+
#define LISTdo_n(list, elt, type, uniq) \
98+
{struct Linked_List_ * _ ## uniq ## l = (list); \
99+
type elt; \
100+
Link _ ## uniq ## p; \
101+
if( _ ## uniq ## l ) { \
102+
for( _ ## uniq ## p = _ ## uniq ## l->mark; \
103+
( _ ## uniq ## p = _ ## uniq ## p->next ) != _ ## uniq ## l->mark; ) { \
104+
( elt ) = ( type ) ( ( _ ## uniq ## p )->data );
99105

100106
#define LISTdo_links(list, link) \
101107
{Linked_List __i = (list); \

0 commit comments

Comments
 (0)