From: Lennart Poettering Date: Tue, 3 Dec 2013 15:41:06 +0000 (+0100) Subject: macro: better make IN_SET() macro use const arrays X-Git-Tag: v209~1138 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=059d9fbb5a691ced7428cff5ff1da5681cacf6da macro: better make IN_SET() macro use const arrays --- diff --git a/src/shared/macro.h b/src/shared/macro.h index 54b641be2..419809501 100644 --- a/src/shared/macro.h +++ b/src/shared/macro.h @@ -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; \ })