Skip to content

Better handling of ## __VA_ARGS__  #279

@escherstair

Description

@escherstair

File trice.h

trice/pkg/src/trice.h

Lines 224 to 225 in 7d9c776

//! 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions