chiark / gitweb /
macro: better make IN_SET() macro use const arrays
authorLennart Poettering <lennart@poettering.net>
Tue, 3 Dec 2013 15:41:06 +0000 (16:41 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 3 Dec 2013 15:41:15 +0000 (16:41 +0100)
src/shared/macro.h

index 54b641be2361593e9d2b57625e5450aea626817f..4198095011c0750437c44041de5cc8d92ac314be 100644 (file)
@@ -285,16 +285,17 @@ do {                                                                    \
 #define SET_FLAG(v, flag, b) \
         (v) = (b) ? ((v) | (flag)) : ((v) & ~(flag))
 
-#define IN_SET(x, ...) ({                                               \
-        typeof(x) _x = (x);                                             \
-        unsigned _i;                                                    \
-        bool _found = false;                                            \
-        for (_i = 0; _i < sizeof((typeof(_x)[]) { __VA_ARGS__ })/sizeof(typeof(_x)); _i++) \
-                if (((typeof(_x)[]) { __VA_ARGS__ })[_i] == _x) {       \
-                        _found = true;                                  \
-                        break;                                          \
-                }                                                       \
-        _found;                                                         \
+#define IN_SET(x, ...)                                                  \
+        ({                                                              \
+                const typeof(x) _x = (x);                               \
+                unsigned _i;                                            \
+                bool _found = false;                                    \
+                for (_i = 0; _i < sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
+                        if (((const typeof(_x)[]) { __VA_ARGS__ })[_i] == _x) { \
+                                _found = true;                          \
+                                break;                                  \
+                        }                                               \
+                _found;                                                 \
         })