diff options
| -rw-r--r-- | src/utils.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/utils.h b/src/utils.h index 5aa2915..69a4259 100644 --- a/src/utils.h +++ b/src/utils.h | |||
| @@ -54,12 +54,16 @@ void collection_remove(struct collection *col, void *element); | |||
| 54 | int collection_count(struct collection *col); | 54 | int collection_count(struct collection *col); |
| 55 | void collection_free(struct collection *col); | 55 | void collection_free(struct collection *col); |
| 56 | 56 | ||
| 57 | #define MERGE_(a,b) a ## _ ## b | ||
| 58 | #define LABEL_(a,b) MERGE_(a, b) | ||
| 59 | #define UNIQUE_VAR(a) LABEL_(a, __LINE__) | ||
| 60 | |||
| 57 | #define FOREACH(var, col) \ | 61 | #define FOREACH(var, col) \ |
| 58 | do { \ | 62 | do { \ |
| 59 | int _iter; \ | 63 | int UNIQUE_VAR(_iter); \ |
| 60 | for(_iter=0; _iter<(col)->capacity; _iter++) { \ | 64 | for(UNIQUE_VAR(_iter)=0; UNIQUE_VAR(_iter)<(col)->capacity; UNIQUE_VAR(_iter)++) { \ |
| 61 | if(!(col)->list[_iter]) continue; \ | 65 | if(!(col)->list[UNIQUE_VAR(_iter)]) continue; \ |
| 62 | var = (col)->list[_iter]; | 66 | var = (col)->list[UNIQUE_VAR(_iter)]; |
| 63 | 67 | ||
| 64 | #define ENDFOREACH \ | 68 | #define ENDFOREACH \ |
| 65 | } \ | 69 | } \ |
