diff options
author | Thomas Haller <thaller@redhat.com> | 2015-08-12 13:04:12 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-08-12 16:04:17 +0200 |
commit | 96cacc07e8f0a30dbb25d31000751624cf1e6a8e (patch) | |
tree | 01d81530def9bb61be851e0c5121df2ef7270c13 /include | |
parent | 7860ef959ae4b244017b9dc491e9c0a6024279dd (diff) | |
download | NetworkManager-96cacc07e8f0a30dbb25d31000751624cf1e6a8e.tar.gz |
macros: use short-circuit evaluation in NM_IN_SET()
All current users of NM_IN_SET() would rather use short-circuit evalation
(or don't care). It seems that doing it by default seems favorable.
The only downside is, that this might have somewhat unexpected behavior
to a user who expects a regular function (which would evaluate always
all arguments).
Fixes: 7860ef959ae4b244017b9dc491e9c0a6024279dd
Diffstat (limited to 'include')
-rw-r--r-- | include/nm-macros-internal.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/include/nm-macros-internal.h b/include/nm-macros-internal.h index fe45787d2d..291dc0742a 100644 --- a/include/nm-macros-internal.h +++ b/include/nm-macros-internal.h @@ -159,13 +159,15 @@ #define _NM_IN_SET_EVAL_N2(op, x, n, ...) _NM_IN_SET_EVAL_##n(op, x, __VA_ARGS__) #define _NM_IN_SET_EVAL_N(op, x, n, ...) _NM_IN_SET_EVAL_N2(op, x, n, __VA_ARGS__) -/* does not do short-circuit evaluation to get a more function-like behavior - * ("|" instead of "||"). Use NM_IN_SET_SC() if you want that */ -#define NM_IN_SET(x, ...) _NM_IN_SET_EVAL_N(| , x, NM_NARG (__VA_ARGS__), __VA_ARGS__) - -/* "SC" stands for "short-cirtuit". It will only evaluate the arguments - * until a match is found. */ -#define NM_IN_SET_SC(x, ...) _NM_IN_SET_EVAL_N(||, x, NM_NARG (__VA_ARGS__), __VA_ARGS__) +/* Beware that this does short-circuit evaluation (use "||" instead of "|") + * which has a possibly unexpected non-function-like behavior. + * Use NM_IN_SET_SE if you need all arguments to be evaluted. */ +#define NM_IN_SET(x, ...) _NM_IN_SET_EVAL_N(||, x, NM_NARG (__VA_ARGS__), __VA_ARGS__) + +/* "SE" stands for "side-effect". Contrary to NM_IN_SET(), this does not do + * short-circuit evaluation, which can make a difference if the arguments have + * side-effects. */ +#define NM_IN_SET_SE(x, ...) _NM_IN_SET_EVAL_N(|, x, NM_NARG (__VA_ARGS__), __VA_ARGS__) /*****************************************************************************/ |