[ovs-dev] [PATCH 2/5] lib/flow: Use C99 declaration in for statement.

Jarno Rajahalme jrajahalme at nicira.com
Fri May 23 00:37:39 UTC 2014


C99 declarations within code are allowed now.  Change the
FLOW_FOR_EACH_IN_MAP to use loop variable within the for statement.
This makes this macro more generally useful.

The loop variable name is suffixed with two underscores with the
intention that there would be a low likelihood of collision with any
of the macro parameters.

Also fix the return type of flow_get_next_in_map().

Signed-off-by: Jarno Rajahalme <jrajahalme at nicira.com>
---
 lib/flow.h |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/lib/flow.h b/lib/flow.h
index 0f3ffde..139e7f6 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -411,7 +411,7 @@ void miniflow_destroy(struct miniflow *);
 
 void miniflow_expand(const struct miniflow *, struct flow *);
 
-static inline uint32_t
+static inline bool
 flow_get_next_in_map(const struct flow *flow, uint64_t map, uint32_t *value)
 {
     if (map) {
@@ -421,13 +421,11 @@ flow_get_next_in_map(const struct flow *flow, uint64_t map, uint32_t *value)
     return false;
 }
 
-/* Iterate through all flow u32 values specified by 'MAP'.
- * This works as the first statement in a block.*/
-#define FLOW_FOR_EACH_IN_MAP(VALUE, FLOW, MAP)                          \
-    uint64_t map_;                                                      \
-    for (map_ = (MAP);                                                  \
-         flow_get_next_in_map(FLOW, map_, &(VALUE));                    \
-         map_ = zero_rightmost_1bit(map_))
+/* Iterate through all flow u32 values specified by 'MAP'. */
+#define FLOW_FOR_EACH_IN_MAP(VALUE, FLOW, MAP)         \
+    for (uint64_t map__ = (MAP);                       \
+         flow_get_next_in_map(FLOW, map__, &(VALUE));  \
+         map__ = zero_rightmost_1bit(map__))
 
 #define FLOW_U32_SIZE(FIELD)                                            \
     DIV_ROUND_UP(sizeof(((struct flow *)0)->FIELD), sizeof(uint32_t))
-- 
1.7.10.4




More information about the dev mailing list