summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2013-09-30 15:25:17 +0200
committerGravatar Nikias Bassen2013-09-30 15:25:17 +0200
commit4847a1161c712e6e56287b367296cc837bcd6b0a (patch)
tree959607ac62c13c0e7cc21232fd915803a4cc6e62
parent1b775742ecee394050eac12f71562acf9e7c1294 (diff)
downloadusbmuxd-4847a1161c712e6e56287b367296cc837bcd6b0a.tar.gz
usbmuxd-4847a1161c712e6e56287b367296cc837bcd6b0a.tar.bz2
utils: make FOREACH macro _iter variable unique
-rw-r--r--src/utils.h12
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);
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 \
} \