Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.std.c Subject: Re: Why doesn't __VA_LIST__ just eat the prior comma? Date: Tue, 19 Apr 2022 02:04:36 -0700 Organization: A noiseless patient Spider Lines: 22 Message-ID: <861qxta1gb.fsf@linuxsc.com> References: <20220413165157.844@kylheku.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="dca78489ef0b00bc0e84cad62da1ae52"; logging-data="20574"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LHuRw5OrqTjaWqrVio5BrLCtWd1Ro6i0=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:coSXZqNNssDjeDkUa1AqGGOG4Jg= sha1:rZG0t51L3MfwOmd/QFAEfrh/a04= Xref: csiph.com comp.std.c:6434 Kaz Kylheku <480-992-1380@kylheku.com> writes: > 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? This idea is considered in section "Alternative Designs" of http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2160.htm