Kaz Kylheku
2022-04-14 00:01:37 UTC
There is a well-known problem that a macro like
#define foo(x, ...) something(whatever, __VA_ARGS__)
cannot work when the trailing argument list is empty because
you get the expansion something(whatever, )
GNU C provides ##__VA_ARGS__ which behaves like __VA_ARGS__ in
the nonempty case, and eats the prior comma in the empty case.
C++20 provides __VA_OPT__ which is used like __VA_OPT__(,) to
conditionally eat the comma. (GNU C has this also).
The question is: why wouldn't you just fix the semantics of __VA_ARG__
so that this is not necessary?
When would you ever want to interpolate __VA_ARGS__ into a replacement
sequence such that if it is empty, and placed after a comma, that
comma does not disappear?
#define foo(x, ...) something(whatever, __VA_ARGS__)
cannot work when the trailing argument list is empty because
you get the expansion something(whatever, )
GNU C provides ##__VA_ARGS__ which behaves like __VA_ARGS__ in
the nonempty case, and eats the prior comma in the empty case.
C++20 provides __VA_OPT__ which is used like __VA_OPT__(,) to
conditionally eat the comma. (GNU C has this also).
The question is: why wouldn't you just fix the semantics of __VA_ARG__
so that this is not necessary?
When would you ever want to interpolate __VA_ARGS__ into a replacement
sequence such that if it is empty, and placed after a comma, that
comma does not disappear?
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal