Date: Sun, 6 Dec 2026 18:01:44 +0100
On 11/27/26 1:44 PM, Alejandro Colomar via Std-Proposals wrote:
> Hi Jan,
>
>> Date: 2026-11-27 07:38:08+0100
>> From: Jan Schultke <janschultke_at_[hidden]>
>>
>> Hi Alejandro,
>>
>> I would like you to draw your attention to
>> https://isocpp.org/files/papers/P3776R1.html#claiming-syntax-space
>
> Thanks!
>
>> The idea of using "empty arguments" for default arguments was brought up a
>> bunch when I discussed P3776, but it always seemed like a footnote and like
>> no one could seriously suggest it and like it wouldn't find consensus. The
>> idea doesn't preclude trailing commas (or vice versa), but it shares the
>> same syntax space.
>
> Hmmm, indeed.
>
> Some interesting paragraph in that paper is
>
> Firstly, note that f(1,) has the effect of passing a default
> argument for y, no matter the meaning of a trailing comma.
> f(1,1,) would be a special case, but in principle, trailing
> commas are compatible with these hypothetical semantics.
>
> The first sentence seems to show that if trailing commas are ever given
> a meaning, it should be default arguments, and that being claimed for
> default arguments, I'd avoid allowing trailing commas for other meanings
> (such as being ignored).
>
>> I would like it a lot more if you used some token to request default
>> arguments, like f(default, 0). default is a keyword already and expresses
>> the intent, so it seems quite suitable. I'm not yet convinced that the
>> problem is big enough to warrant this language change, but I would find
>> such a syntax acceptable.
>
> Hmmm, yeah, so two people here have expressed preference for 'default'.
> When implementing this with macros in C, I also tried first to use the
> 'default' keyword, but I couldn't find a way to do it.
>
> So, I think 'default' seems preferable. I wish it was a bit shorter,
> since it takes 7 characters (plus a space) for just taking a default
> value, but I can live with it. The other major caveat is that it's not
> backwards compatible, unlike empty args. But I'm okay with it.
>
> BTW, does anyone have an idea of how it could be implemented with macros
> backwards compatibly? I think it's not possible, but maybe someone has
> an idea. (Actually, one could stringify it, and then have a conditional
> comparing "default" with the argument, before evaluating it, but I'm
> looking for a zero-cost implementation.)
#define DEFARG_CAT_(a, b) a ## b
#define DEFARG_CAT(a, b) DEFARG_CAT_(a, b)
#define DEFARG_SECOND_(a, b, ...) b
#define DEFARG_SECOND(...) DEFARG_SECOND_(__VA_ARGS__)
#define DEFARG_PROBE_default ~, 1
#define DEFARG_PROBE_ ~, 1 /* if an empty argument also
selects the default */
#define DEFARG_PAREN_PROBE(...) ~, 1,
#define DEFARG_IS_PAREN(x) DEFARG_SECOND(DEFARG_PAREN_PROBE x, 0, ~)
#define DEFARG_CHECK_1(x) 0
#define DEFARG_CHECK_0(x) DEFARG_SECOND(DEFARG_PROBE_ ## x, 0, ~)
#define DEFARG_IS_DEFAULT(x) DEFARG_CAT(DEFARG_CHECK_,
DEFARG_IS_PAREN(x))(x)
#define DEFARG_IF_0(def, arg) (arg)
#define DEFARG_IF_1(def, arg) (def)
#define DEFARG(def, arg) DEFARG_CAT(DEFARG_IF_,
DEFARG_IS_DEFAULT(arg))(def, arg)
(but the expanded argument has to either start with a paren or have the
first token be a valid suffix to an identifier or else it'll hard error
(e.g. -1, 1.5, *p, &x, !b, ~0, 1e-3, 1'000, 'c', "s", etc. don't work),
which does make use with those mandate that they be put between parens)
(note: i don't believe the "has to be a valid suffix to an identifier"
limitation can be meaningfully fixed, sadly - it does at least only
apply to the arg side; DEFARG(-1, n) is fine)
>
>
> Have a lovely day!
> Alex
>
>>
>>
>> Jan
>>
>>
>> On Thu, 26 Nov 2026 at 12:47, Alejandro Colomar via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>
>>> Hi!
>>>
>>> I implement default arguments in C with macros and a simple trick of
>>> reversing the arguments. Here's some example:
>>>
>>> #include <stdio.h>
>>>
>>> #define DEFARG(def, arg) DEFARG_(def, arg)
>>> #define DEFARG_(def, ...) DEFARG__(__VA_ARGS__ __VA_OPT__(,) def)
>>> #define DEFARG__(x, ...) (x)
>>>
>>> #define snprintf(s, n, ...) snprintf(s, DEFARG(_Countof(s), n),
>>> __VA_ARGS__)
>>>
>>> int
>>> main(void)
>>> {
>>> char buf[42];
>>>
>>> snprintf(buf, , "%s%s", "foo", "bar");
>>> printf("%s\n", buf);
>>> }
>>>
>>> The default value is invoked by passing an empty argument, as can be
>>> seen in the snprintf(3) call above. The mandatory empty argument makes
>>> it safer than a completely omitted argument, as the compiler doesn't
>>> need to go guessing what we meant. See also
>>> <https://lore.kernel.org/lkml/abhGS0n_RsUG97Ni_at_[hidden]/> for a discussion
>>> about a use of C++-style default arguments in the kernel, which ends up
>>> being dangerous, and which would have been safer with mandatory empty
>>> arguments.
>>>
>>> Currently, in C++, default arguments are only allowed at the end of
>>> a function, precisely because with omitted arguments it's not easy for
>>> the compiler to know what to do.
>>>
>>> I propose allowing default arguments in non-trailing parameters, and
>>> requiring that the argument is passed as empty for invoking the default
>>> value.
>>>
>>> Here's how the example from above behaves:
>>>
>>> alx_at_devuan:~/tmp$ gcc -Wall -Wextra -E snprintf.c | tail
>>>
>>> # 10 "snprintf.c"
>>> int
>>> main(void)
>>> {
>>> char buf[42];
>>>
>>> snprintf(buf, (_Countof(buf)), "%s%s", "foo", "bar");
>>> printf("%s\n", buf);
>>> }
>>> alx_at_devuan:~/tmp$ gcc -Wall -Wextra snprintf.c
>>> alx_at_devuan:~/tmp$ ./a.out
>>> foobar
>>>
>>>
>>> The proposal for C++ would then be so that one can write code like this:
>>>
>>> int foo(int a = 42, int b);
>>>
>>> And call it as
>>>
>>> foo(, 7); // Evaluates as foo(42,7)
>>>
>>> This would replace some cases which are currently handled with
>>> overloads, which are a much heavier machinery (and also more difficult
>>> to diagnose).
>>>
>>>
>>> What do you think?
>>>
>>>
>>> Have a lovely day!
>>> Alex
>>>
>>> --
>>> <https://www.alejandro-colomar.es>
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>
>
>
> Hi Jan,
>
>> Date: 2026-11-27 07:38:08+0100
>> From: Jan Schultke <janschultke_at_[hidden]>
>>
>> Hi Alejandro,
>>
>> I would like you to draw your attention to
>> https://isocpp.org/files/papers/P3776R1.html#claiming-syntax-space
>
> Thanks!
>
>> The idea of using "empty arguments" for default arguments was brought up a
>> bunch when I discussed P3776, but it always seemed like a footnote and like
>> no one could seriously suggest it and like it wouldn't find consensus. The
>> idea doesn't preclude trailing commas (or vice versa), but it shares the
>> same syntax space.
>
> Hmmm, indeed.
>
> Some interesting paragraph in that paper is
>
> Firstly, note that f(1,) has the effect of passing a default
> argument for y, no matter the meaning of a trailing comma.
> f(1,1,) would be a special case, but in principle, trailing
> commas are compatible with these hypothetical semantics.
>
> The first sentence seems to show that if trailing commas are ever given
> a meaning, it should be default arguments, and that being claimed for
> default arguments, I'd avoid allowing trailing commas for other meanings
> (such as being ignored).
>
>> I would like it a lot more if you used some token to request default
>> arguments, like f(default, 0). default is a keyword already and expresses
>> the intent, so it seems quite suitable. I'm not yet convinced that the
>> problem is big enough to warrant this language change, but I would find
>> such a syntax acceptable.
>
> Hmmm, yeah, so two people here have expressed preference for 'default'.
> When implementing this with macros in C, I also tried first to use the
> 'default' keyword, but I couldn't find a way to do it.
>
> So, I think 'default' seems preferable. I wish it was a bit shorter,
> since it takes 7 characters (plus a space) for just taking a default
> value, but I can live with it. The other major caveat is that it's not
> backwards compatible, unlike empty args. But I'm okay with it.
>
> BTW, does anyone have an idea of how it could be implemented with macros
> backwards compatibly? I think it's not possible, but maybe someone has
> an idea. (Actually, one could stringify it, and then have a conditional
> comparing "default" with the argument, before evaluating it, but I'm
> looking for a zero-cost implementation.)
#define DEFARG_CAT_(a, b) a ## b
#define DEFARG_CAT(a, b) DEFARG_CAT_(a, b)
#define DEFARG_SECOND_(a, b, ...) b
#define DEFARG_SECOND(...) DEFARG_SECOND_(__VA_ARGS__)
#define DEFARG_PROBE_default ~, 1
#define DEFARG_PROBE_ ~, 1 /* if an empty argument also
selects the default */
#define DEFARG_PAREN_PROBE(...) ~, 1,
#define DEFARG_IS_PAREN(x) DEFARG_SECOND(DEFARG_PAREN_PROBE x, 0, ~)
#define DEFARG_CHECK_1(x) 0
#define DEFARG_CHECK_0(x) DEFARG_SECOND(DEFARG_PROBE_ ## x, 0, ~)
#define DEFARG_IS_DEFAULT(x) DEFARG_CAT(DEFARG_CHECK_,
DEFARG_IS_PAREN(x))(x)
#define DEFARG_IF_0(def, arg) (arg)
#define DEFARG_IF_1(def, arg) (def)
#define DEFARG(def, arg) DEFARG_CAT(DEFARG_IF_,
DEFARG_IS_DEFAULT(arg))(def, arg)
(but the expanded argument has to either start with a paren or have the
first token be a valid suffix to an identifier or else it'll hard error
(e.g. -1, 1.5, *p, &x, !b, ~0, 1e-3, 1'000, 'c', "s", etc. don't work),
which does make use with those mandate that they be put between parens)
(note: i don't believe the "has to be a valid suffix to an identifier"
limitation can be meaningfully fixed, sadly - it does at least only
apply to the arg side; DEFARG(-1, n) is fine)
>
>
> Have a lovely day!
> Alex
>
>>
>>
>> Jan
>>
>>
>> On Thu, 26 Nov 2026 at 12:47, Alejandro Colomar via Std-Proposals <
>> std-proposals_at_[hidden]> wrote:
>>
>>> Hi!
>>>
>>> I implement default arguments in C with macros and a simple trick of
>>> reversing the arguments. Here's some example:
>>>
>>> #include <stdio.h>
>>>
>>> #define DEFARG(def, arg) DEFARG_(def, arg)
>>> #define DEFARG_(def, ...) DEFARG__(__VA_ARGS__ __VA_OPT__(,) def)
>>> #define DEFARG__(x, ...) (x)
>>>
>>> #define snprintf(s, n, ...) snprintf(s, DEFARG(_Countof(s), n),
>>> __VA_ARGS__)
>>>
>>> int
>>> main(void)
>>> {
>>> char buf[42];
>>>
>>> snprintf(buf, , "%s%s", "foo", "bar");
>>> printf("%s\n", buf);
>>> }
>>>
>>> The default value is invoked by passing an empty argument, as can be
>>> seen in the snprintf(3) call above. The mandatory empty argument makes
>>> it safer than a completely omitted argument, as the compiler doesn't
>>> need to go guessing what we meant. See also
>>> <https://lore.kernel.org/lkml/abhGS0n_RsUG97Ni_at_[hidden]/> for a discussion
>>> about a use of C++-style default arguments in the kernel, which ends up
>>> being dangerous, and which would have been safer with mandatory empty
>>> arguments.
>>>
>>> Currently, in C++, default arguments are only allowed at the end of
>>> a function, precisely because with omitted arguments it's not easy for
>>> the compiler to know what to do.
>>>
>>> I propose allowing default arguments in non-trailing parameters, and
>>> requiring that the argument is passed as empty for invoking the default
>>> value.
>>>
>>> Here's how the example from above behaves:
>>>
>>> alx_at_devuan:~/tmp$ gcc -Wall -Wextra -E snprintf.c | tail
>>>
>>> # 10 "snprintf.c"
>>> int
>>> main(void)
>>> {
>>> char buf[42];
>>>
>>> snprintf(buf, (_Countof(buf)), "%s%s", "foo", "bar");
>>> printf("%s\n", buf);
>>> }
>>> alx_at_devuan:~/tmp$ gcc -Wall -Wextra snprintf.c
>>> alx_at_devuan:~/tmp$ ./a.out
>>> foobar
>>>
>>>
>>> The proposal for C++ would then be so that one can write code like this:
>>>
>>> int foo(int a = 42, int b);
>>>
>>> And call it as
>>>
>>> foo(, 7); // Evaluates as foo(42,7)
>>>
>>> This would replace some cases which are currently handled with
>>> overloads, which are a much heavier machinery (and also more difficult
>>> to diagnose).
>>>
>>>
>>> What do you think?
>>>
>>>
>>> Have a lovely day!
>>> Alex
>>>
>>> --
>>> <https://www.alejandro-colomar.es>
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>>
>
>
Received on 2026-12-06 17:01:52
