Browse Source

Use token-pasting magic to make nested SMARTLIST_FOREACH work.

svn:r2526
Nick Mathewson 21 years ago
parent
commit
5e80944c52
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/common/util.h

+ 4 - 3
src/common/util.h

@@ -149,10 +149,11 @@ char *smartlist_join_strings(smartlist_t *sl, const char *join, int terminate);
 
 #define SMARTLIST_FOREACH(sl, type, var, cmd)                   \
   do {                                                          \
-    int sl_idx, sl_len=smartlist_len(sl);                       \
+    int var ## _sl_idx, var ## _sl_len=smartlist_len(sl);       \
     type var;                                                   \
-    for(sl_idx = 0; sl_idx < sl_len; ++sl_idx) {                \
-      var = smartlist_get((sl),sl_idx);                         \
+    for(var ## _sl_idx = 0; var ## _sl_idx < var ## _sl_len;    \
+        ++var ## _sl_idx) {                                     \
+      var = smartlist_get((sl),var ## _sl_idx);                 \
       do {cmd;} while(0);                                       \
     } } while (0)