Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Don't tell me how hard you work. Tell me how much you get done. -- James J. Ling


devel / comp.std.c / Why doesn't __VA_LIST__ just eat the prior comma?

SubjectAuthor
* Why doesn't __VA_LIST__ just eat the prior comma?Kaz Kylheku
+* Re: Why doesn't __VA_LIST__ just eat the prior comma?Ben
|`* Re: Why doesn't __VA_LIST__ just eat the prior comma?Kaz Kylheku
| `- Re: Why doesn't __VA_LIST__ just eat the prior comma?Ben
`* Re: Why doesn't __VA_LIST__ just eat the prior comma?Tim Rentsch
 `* Re: Why doesn't __VA_LIST__ just eat the prior comma?Kaz Kylheku
  `- Re: Why doesn't __VA_LIST__ just eat the prior comma?Tim Rentsch

1
Why doesn't __VA_LIST__ just eat the prior comma?

<20220413165157.844@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=452&group=comp.std.c#452

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.std.c
Subject: Why doesn't __VA_LIST__ just eat the prior comma?
Date: Thu, 14 Apr 2022 00:01:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <20220413165157.844@kylheku.com>
Injection-Date: Thu, 14 Apr 2022 00:01:37 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="823c5dc8aa629ee253d481526a6b22f4";
logging-data="9106"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19305WC6WkV+iEtqx+b/ysbM8hPaPI1NXA="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Wd1+Y0EineskoXWSpX2Hms8WJV4=
 by: Kaz Kylheku - Thu, 14 Apr 2022 00:01 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?

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Why doesn't __VA_LIST__ just eat the prior comma?

<87czhju7ml.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=453&group=comp.std.c#453

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.std.c
Subject: Re: Why doesn't __VA_LIST__ just eat the prior comma?
Date: Thu, 14 Apr 2022 14:17:22 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <87czhju7ml.fsf@bsb.me.uk>
References: <20220413165157.844@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="d24b48f9c0b0cf8c127841564518bd44";
logging-data="15678"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7ShJD5BvNPay1n7FWaolcCXFUeD+smUk="
Cancel-Lock: sha1:qHCIaf6SpIiccHSXsdHxkhyhf1Y=
sha1:jXG3VuhQ84v4ROSlMwePUUgGxO4=
X-BSB-Auth: 1.daf7ab63f5fe39a2ce72.20220414141722BST.87czhju7ml.fsf@bsb.me.uk
 by: Ben - Thu, 14 Apr 2022 13:17 UTC

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?
>
> 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?

You might not want it (as a design feature), but there is probably code
out there that now depends on it. The C committee is very reluctant to
break existing code, especially where the fix is more complex than
"search for 'restrict' to check it's not used".

--
Ben.

Re: Why doesn't __VA_LIST__ just eat the prior comma?

<20220418093916.295@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=454&group=comp.std.c#454

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.std.c
Subject: Re: Why doesn't __VA_LIST__ just eat the prior comma?
Date: Mon, 18 Apr 2022 16:59:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <20220418093916.295@kylheku.com>
References: <20220413165157.844@kylheku.com> <87czhju7ml.fsf@bsb.me.uk>
Injection-Date: Mon, 18 Apr 2022 16:59:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="6aab72b3d451db54ac71f617edd25812";
logging-data="9125"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19g6gokgVszvg2NhwlGUVV16TTtrPQnSWo="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:Cy1A27EQF7LVqOHojHwxrABMW1w=
 by: Kaz Kylheku - Mon, 18 Apr 2022 16:59 UTC

On 2022-04-14, Ben <ben.usenet@bsb.me.uk> wrote:
> 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?
>>
>> 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?
>
> You might not want it (as a design feature), but there is probably code
> out there that now depends on it.

That's my question: what is the form of this dependency? What is an
example of something that breaks if __VA_ARGS__ eats the prior comma
when it has an empty expansion?

Of course, we can write regression test cases which verify that
the comma is not eaten, and I can think of ways of doing that:

#define mac(...) foo(, __VA_ARGS__)
#define xstr(x) str(x)
#define str(x) #x

assert (strcmp(xstr(mac()), "foo(, )") == 0);

printf("%s\n", xstr(mac()));

I mean, some way of relying on the comma that is actually useful.

If I wanted to stringify mac() for some useful purpose in some real
program, I would actually prefer the result "foo( )" or "foo()".
I'd likely need a post-processing run-time pass to convert "(, )"
occurrences to "()". I'd probably have some conditionals to do it
in the preprocessor, so that the post-processing code can be
compiled out.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Why doesn't __VA_LIST__ just eat the prior comma?

<87bkwygotu.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=455&group=comp.std.c#455

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben)
Newsgroups: comp.std.c
Subject: Re: Why doesn't __VA_LIST__ just eat the prior comma?
Date: Mon, 18 Apr 2022 20:43:09 +0100
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <87bkwygotu.fsf@bsb.me.uk>
References: <20220413165157.844@kylheku.com> <87czhju7ml.fsf@bsb.me.uk>
<20220418093916.295@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="5226e2c4a5c0033356b72e0f148905d7";
logging-data="3038"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+u7IoEw/77CdFs9JO36PQjgG/1U0gYOAk="
Cancel-Lock: sha1:UUrsCqXqZwRESq7mITDsm0A4Q2s=
sha1:/26vaXn0ETvSQHrMEtDNKeoICTc=
X-BSB-Auth: 1.a99028c6289f49c1034c.20220418204309BST.87bkwygotu.fsf@bsb.me.uk
 by: Ben - Mon, 18 Apr 2022 19:43 UTC

Kaz Kylheku <480-992-1380@kylheku.com> writes:

> On 2022-04-14, Ben <ben.usenet@bsb.me.uk> wrote:
>> 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?
>>>
>>> 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?
>>
>> You might not want it (as a design feature), but there is probably code
>> out there that now depends on it.
>
> That's my question: what is the form of this dependency? What is an
> example of something that breaks if __VA_ARGS__ eats the prior comma
> when it has an empty expansion?

I don't know of an example.

> Of course, we can write regression test cases which verify that
> the comma is not eaten, and I can think of ways of doing that:
>
> #define mac(...) foo(, __VA_ARGS__)
> #define xstr(x) str(x)
> #define str(x) #x
>
> assert (strcmp(xstr(mac()), "foo(, )") == 0);
>
> printf("%s\n", xstr(mac()));
>
> I mean, some way of relying on the comma that is actually useful.

The code does not have to find it actually useful for it to break on a
change. If someone, somewhere, ended up having to work around this
issue, that code will break even if the programmer might now be glad of
the opportunity to simplify it.

--
Ben.

Re: Why doesn't __VA_LIST__ just eat the prior comma?

<861qxta1gb.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=456&group=comp.std.c#456

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (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=
 by: Tim Rentsch - Tue, 19 Apr 2022 09:04 UTC

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

Re: Why doesn't __VA_LIST__ just eat the prior comma?

<20220419183244.563@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=457&group=comp.std.c#457

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.std.c
Subject: Re: Why doesn't __VA_LIST__ just eat the prior comma?
Date: Wed, 20 Apr 2022 02:02:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <20220419183244.563@kylheku.com>
References: <20220413165157.844@kylheku.com> <861qxta1gb.fsf@linuxsc.com>
Injection-Date: Wed, 20 Apr 2022 02:02:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="328c6955eaea4a2d6cff2d3767937281";
logging-data="8782"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kLuPIx3bYxeDUiHwEbS4EW5QY9I03Zzg="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:JoyRPsNG7PnJb/9Y3klJLQX52v4=
 by: Kaz Kylheku - Wed, 20 Apr 2022 02:02 UTC

On 2022-04-19, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
> 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

Fantastic; thanks for that link!

The crux is that, for whatever reason, a macro like:

#define ADD_COMMA(...) , __VA_ARGS__

is tabled as an important requirement, and for that reason, F()
expanding to f(10), though identified as desirable, is not considered;
the automatic comma eating would break ADD_COMMA.

But! I think that could be acceptably handled like this:

#define FENCE
#define ADD_COMMA(...) , FENCE __VA_ARGS__

The rule that __VA_ARGS__ consumes the comma would be carried out
prior to the macro replacement of the token replacement sequence,
during which time FENCE is still there. Since FENCE doesn't look like
a comma, all is cool.

(This seems natural because the substitution of __VA_ARGS__ should in fact
be taking place during argument replacement, and not during the
rescanning of the argument-substituted replacement sequence for more
macros.)

Re: Why doesn't __VA_LIST__ just eat the prior comma?

<86a6bk3tm7.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=459&group=comp.std.c#459

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.std.c
Subject: Re: Why doesn't __VA_LIST__ just eat the prior comma?
Date: Sat, 14 May 2022 10:35:12 -0700
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <86a6bk3tm7.fsf@linuxsc.com>
References: <20220413165157.844@kylheku.com> <861qxta1gb.fsf@linuxsc.com> <20220419183244.563@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="a8bda869c48c5c2b8373a8e0a3aebed4";
logging-data="9494"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ffZxvIEGeWYgMjPaWcgWxkTgEBgNCx90="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:OMyRF7I2tjhgHzZrdjVt1+s5Euw=
sha1:Duu150+Nj/g6d4/mgLLkZw8pU/0=
 by: Tim Rentsch - Sat, 14 May 2022 17:35 UTC

Kaz Kylheku <480-992-1380@kylheku.com> writes:

> On 2022-04-19, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>
>> 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
>
> Fantastic; thanks for that link!
>
> The crux is that, for whatever reason, a macro like:
>
> #define ADD_COMMA(...) , __VA_ARGS__
>
> is tabled as an important requirement, and for that reason, F()
> expanding to f(10), though identified as desirable, is not
> considered; the automatic comma eating would break ADD_COMMA.
>
> But! I think that could be acceptably handled like this:
>
> #define FENCE
> #define ADD_COMMA(...) , FENCE __VA_ARGS__
>
> The rule that __VA_ARGS__ consumes the comma would be carried out
> prior to the macro replacement of the token replacement sequence,
> during which time FENCE is still there. Since FENCE doesn't look
> like a comma, all is cool.

If you feel strongly about it, write up a proposal and submit it
to the two committees. Given that __VA_OPT__ has already been
adopted in C++20, any alternate scheme faces an uphill climb, and
so if no one feels strongly enough to try to get some other
scheme through the standardization process then it seems rather
pointless to discuss it.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor