Skip to content

Commit

Permalink
utils: make FOREACH macro _iter variable unique
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias authored and olunx committed Apr 4, 2014
1 parent 002bf23 commit c9ff0cb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ void collection_remove(struct collection *col, void *element);
int collection_count(struct collection *col);
void collection_free(struct collection *col);

#define MERGE_(a,b) a ## _ ## b
#define LABEL_(a,b) MERGE_(a, b)
#define UNIQUE_VAR(a) LABEL_(a, __LINE__)

#define FOREACH(var, col) \
do { \
int _iter; \
for(_iter=0; _iter<(col)->capacity; _iter++) { \
if(!(col)->list[_iter]) continue; \
var = (col)->list[_iter];
int UNIQUE_VAR(_iter); \
for(UNIQUE_VAR(_iter)=0; UNIQUE_VAR(_iter)<(col)->capacity; UNIQUE_VAR(_iter)++) { \
if(!(col)->list[UNIQUE_VAR(_iter)]) continue; \
var = (col)->list[UNIQUE_VAR(_iter)];

#define ENDFOREACH \
} \
Expand Down

0 comments on commit c9ff0cb

Please sign in to comment.