File trice.h
|
//! The expression `## __VA_ARGS__` ist not supported by older compilers. You can remove the `##` and use TRICE0 instead of TRICE for a no parameter value TRICE in that case. |
|
#define COUNT_ARGUMENTS(...) NTH_ARGUMENT(dummy, ## __VA_ARGS__, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) |
defines
COUNT_ARGUMENTS(...) macro using
## __VA_ARGS__
The comment says
//! The expression ##
VA_ARGS ist not supported by older compilers.
but this is not 100% right.
As far as I know,
## __VA_ARGS__ when
__VA_ARGS__ is empty is handled in a special way by GCC extension (see
here), that strips the comma
, before
##.
But this behavior is not standard C, even if it has been proposed for standardization (see here).
And so, even a "new" clang compiler (not GCC) doesn't support this GCC extension and it requires a manual change to the code as described by the comment
|
//! The expression `## __VA_ARGS__` ist not supported by older compilers. You can remove the `##` and use TRICE0 instead of TRICE for a no parameter value TRICE in that case. |
Please, consider that Arm Compiler 6 is clang-based (not GCCI) and so even the new relase 6.18 (releases on May 2022) requires this change.
I suggest to investigate (and maybe improve) the COUNT_ARGUMENTS(...) macro so that it doesn't rely over a GCC extension.
I try to propose a working solution, even if the readability of the code would be a little be worse.
/* EDIT */
After a deeper investigation it seems that clang supports this behavior too (see here).
I'm going to check why ARM Compiler 6 doesn't behave in this way.
File
trice.htrice/pkg/src/trice.h
Lines 224 to 225 in 7d9c776
defines
COUNT_ARGUMENTS(...)macro using## __VA_ARGS__The comment says
//! The expression## VA_ARGSist not supported by older compilers.but this is not 100% right.
As far as I know,
## __VA_ARGS__when__VA_ARGS__is empty is handled in a special way by GCC extension (see here), that strips the comma,before##.But this behavior is not standard C, even if it has been proposed for standardization (see here).
And so, even a "new" clang compiler (not GCC) doesn't support this GCC extension and it requires a manual change to the code as described by the comment
trice/pkg/src/trice.h
Line 224 in 7d9c776
Please, consider that Arm Compiler 6 is clang-based (not GCCI) and so even the new relase 6.18 (releases on May 2022) requires this change.
I suggest to investigate (and maybe improve) the
COUNT_ARGUMENTS(...)macro so that it doesn't rely over a GCC extension.I try to propose a working solution, even if the readability of the code would be a little be worse.
/* EDIT */
After a deeper investigation it seems that clang supports this behavior too (see here).
I'm going to check why ARM Compiler 6 doesn't behave in this way.