From 6d3dbd239ecd1e3fad328863f1249c33c3ad1858 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 16 Sep 2022 21:26:32 +0200 Subject: [PATCH 1/9] [Bugfix] Handle gcc unsupported __VA_OPT___ macro --- src/IRmacros.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/IRmacros.h b/src/IRmacros.h index 3e074cd11..f2bc490e2 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -5,6 +5,29 @@ */ /// @file IRmacros.h +/** + * PP_NARG() macro get number of arguments provided + * Source: + * http://jonjagger.blogspot.com/2010/11/c-macro-magic-ppnarg.html + * ('base' version) + */ +/// @cond TEST +#define PP_NARG(...) \ + PP_NARG_(__VA_ARGS__, PP_RSEQ_N()) + +#define PP_NARG_(...) \ + PP_ARG_N(__VA_ARGS__) + +#define PP_ARG_N( \ + _1, _2, _3, _4, _5, _6, N, ...) (N) + +#define PP_RSEQ_N() \ + 6,5,4,3,2,1,0 +/// @endcond +/** + * PP_NARG() end + */ + /** * COND() Set of macros to facilitate single-line conditional compilation * argument checking. @@ -13,8 +36,13 @@ * * Usage: * COND([||/&&...], , ) + * + * NB: If __VA_OPT__ macro not supported, the will be expanded! */ /// @cond TEST +#if PP_NARG(__VA_OPT__(,)) != 2 +#define COND(cond, a, b) a +#else #define NOTHING #define EXPAND(...) __VA_ARGS__ #define STUFF_P(a, ...) __VA_OPT__(a) @@ -24,6 +52,7 @@ #define NEGATE(a) VA_TEST(a, a) #define COND_P(cond, a, b) STUFF(a, cond)STUFF(b, NEGATE(cond)) #define COND(cond, a, b) EXPAND(COND_P(cond, a, b)) +#endif /// @endcond /** * end of COND() set of macros From 7a050af9ee01bb99b8db5cc0284914036d4a8619 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Fri, 16 Sep 2022 21:47:40 +0200 Subject: [PATCH 2/9] [Bugfix] Handle gcc unsupported __VA_OPT___ macro, fix linter complaints --- src/IRmacros.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/IRmacros.h b/src/IRmacros.h index f2bc490e2..6b14f0245 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -12,6 +12,9 @@ * ('base' version) */ /// @cond TEST +#ifndef __VA_OPT__ +#define __VA_OPT__(...) +#endif #define PP_NARG(...) \ PP_NARG_(__VA_ARGS__, PP_RSEQ_N()) @@ -22,7 +25,7 @@ _1, _2, _3, _4, _5, _6, N, ...) (N) #define PP_RSEQ_N() \ - 6,5,4,3,2,1,0 + 6, 5, 4, 3, 2, 1, 0 /// @endcond /** * PP_NARG() end @@ -40,7 +43,7 @@ * NB: If __VA_OPT__ macro not supported, the will be expanded! */ /// @cond TEST -#if PP_NARG(__VA_OPT__(,)) != 2 +#if PP_NARG(__VA_OPT__(, )) != 2 #define COND(cond, a, b) a #else #define NOTHING From aaeb6f1f5ba3b55f3aa9e3f6e87ffad7cff836b9 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 17 Sep 2022 10:29:30 +0200 Subject: [PATCH 3/9] [Bugfix] Handle gcc unsupported __VA_OPT___ macro, improved detection macro --- src/IRmacros.h | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/IRmacros.h b/src/IRmacros.h index 6b14f0245..9a6c19eb7 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -6,29 +6,16 @@ /// @file IRmacros.h /** - * PP_NARG() macro get number of arguments provided - * Source: - * http://jonjagger.blogspot.com/2010/11/c-macro-magic-ppnarg.html - * ('base' version) + * VA_OPT_SUPPORTED macro to check if __VA_OPT__ is supported + * Source: https://stackoverflow.com/questions/48045470/ + * portably-detect-va-opt-support + * (answer by cpplearner) */ -/// @cond TEST -#ifndef __VA_OPT__ -#define __VA_OPT__(...) -#endif -#define PP_NARG(...) \ - PP_NARG_(__VA_ARGS__, PP_RSEQ_N()) - -#define PP_NARG_(...) \ - PP_ARG_N(__VA_ARGS__) - -#define PP_ARG_N( \ - _1, _2, _3, _4, _5, _6, N, ...) (N) - -#define PP_RSEQ_N() \ - 6, 5, 4, 3, 2, 1, 0 -/// @endcond +#define PP_THIRD_ARG(a, b, c, ...) c +#define VA_OPT_SUPPORTED_I(...) PP_THIRD_ARG(__VA_OPT__(, ), true, false, ) +#define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?) /** - * PP_NARG() end + * VA_OPT_SUPPORTED end */ /** @@ -43,7 +30,8 @@ * NB: If __VA_OPT__ macro not supported, the will be expanded! */ /// @cond TEST -#if PP_NARG(__VA_OPT__(, )) != 2 +#if !VA_OPT_SUPPORTED +// #pragma message("Compiler without __VA_OPT__ support") #define COND(cond, a, b) a #else #define NOTHING From 349f1fb7bb2bc1a9ac5329cf07c35273b6a287b0 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 17 Sep 2022 10:32:21 +0200 Subject: [PATCH 4/9] [Bugfix] Handle gcc unsupported __VA_OPT___ macro, fix doxygen warnings --- src/IRmacros.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/IRmacros.h b/src/IRmacros.h index 9a6c19eb7..c5004ab83 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -11,9 +11,11 @@ * portably-detect-va-opt-support * (answer by cpplearner) */ +/// @cond TEST #define PP_THIRD_ARG(a, b, c, ...) c #define VA_OPT_SUPPORTED_I(...) PP_THIRD_ARG(__VA_OPT__(, ), true, false, ) #define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?) +/// @endcond /** * VA_OPT_SUPPORTED end */ From 5a5e02f2103094fb5ae832c7279d099db856182d Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 17 Sep 2022 10:35:31 +0200 Subject: [PATCH 5/9] [Bugfix] Handle gcc unsupported __VA_OPT___ macro, fix linter complaints --- src/IRmacros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IRmacros.h b/src/IRmacros.h index c5004ab83..db976bccb 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -13,7 +13,7 @@ */ /// @cond TEST #define PP_THIRD_ARG(a, b, c, ...) c -#define VA_OPT_SUPPORTED_I(...) PP_THIRD_ARG(__VA_OPT__(, ), true, false, ) +#define VA_OPT_SUPPORTED_I(...) PP_THIRD_ARG(__VA_OPT__(,), true, false,) #define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?) /// @endcond /** From 923e5ffc82d1d747e7815907e55fbbf9f0c48df5 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 17 Sep 2022 10:47:45 +0200 Subject: [PATCH 6/9] [Bugfix] Handle gcc unsupported __VA_OPT___ macro, fix linter contradiction --- src/IRmacros.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/IRmacros.h b/src/IRmacros.h index db976bccb..5f2f4c353 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -13,7 +13,8 @@ */ /// @cond TEST #define PP_THIRD_ARG(a, b, c, ...) c -#define VA_OPT_SUPPORTED_I(...) PP_THIRD_ARG(__VA_OPT__(,), true, false,) +#define VA_OPT_SUPPORTED_I(...) \ + PP_THIRD_ARG(__VA_OPT__(, ), true, false, false) #define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?) /// @endcond /** From 6229d150f3c23bac832b9f4911436628b752f0c7 Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 17 Sep 2022 10:57:47 +0200 Subject: [PATCH 7/9] [Bugfix] Handle gcc unsupported __VA_OPT___ macro, fix linter contradiction --- src/IRmacros.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IRmacros.h b/src/IRmacros.h index 5f2f4c353..d64e76d4e 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -14,7 +14,7 @@ /// @cond TEST #define PP_THIRD_ARG(a, b, c, ...) c #define VA_OPT_SUPPORTED_I(...) \ - PP_THIRD_ARG(__VA_OPT__(, ), true, false, false) + PP_THIRD_ARG(__VA_OPT__(, false), true, false, false) #define VA_OPT_SUPPORTED VA_OPT_SUPPORTED_I(?) /// @endcond /** From aaab2330ed9064efe912476993386ab30a7f953c Mon Sep 17 00:00:00 2001 From: Ton Huisman Date: Sat, 17 Sep 2022 13:50:17 +0200 Subject: [PATCH 8/9] [Bugfix] Handle gcc unsupported __VA_OPT___ macro, link directly to source (SO answer) --- src/IRmacros.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/IRmacros.h b/src/IRmacros.h index d64e76d4e..2c2ad7d94 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -7,9 +7,7 @@ /** * VA_OPT_SUPPORTED macro to check if __VA_OPT__ is supported - * Source: https://stackoverflow.com/questions/48045470/ - * portably-detect-va-opt-support - * (answer by cpplearner) + * Source: https://stackoverflow.com/a/48045656 */ /// @cond TEST #define PP_THIRD_ARG(a, b, c, ...) c From 0fef273a34d3f5d54071d9901d5b24fed4eca4a1 Mon Sep 17 00:00:00 2001 From: David Conran Date: Sun, 18 Sep 2022 14:24:58 +1000 Subject: [PATCH 9/9] Minor commenting style tweak Comment the specific points of the `#if` preprocessort statements --- src/IRmacros.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/IRmacros.h b/src/IRmacros.h index 2c2ad7d94..665286298 100644 --- a/src/IRmacros.h +++ b/src/IRmacros.h @@ -34,7 +34,7 @@ #if !VA_OPT_SUPPORTED // #pragma message("Compiler without __VA_OPT__ support") #define COND(cond, a, b) a -#else +#else // !VA_OPT_SUPPORTED #define NOTHING #define EXPAND(...) __VA_ARGS__ #define STUFF_P(a, ...) __VA_OPT__(a) @@ -44,7 +44,7 @@ #define NEGATE(a) VA_TEST(a, a) #define COND_P(cond, a, b) STUFF(a, cond)STUFF(b, NEGATE(cond)) #define COND(cond, a, b) EXPAND(COND_P(cond, a, b)) -#endif +#endif // !VA_OPT_SUPPORTED /// @endcond /** * end of COND() set of macros