https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33877

--- Comment #8 from Alejandro Colomar <foss+...@alejandro-colomar.es> ---
(In reply to Harald van Dijk from comment #7)
> (In reply to Alejandro Colomar from comment #6)
> > Please make sure to differentiate correctly the case of 0 and 1 arguments.
> > 
> > #define foo(...)     __VA_ARGC__
> > #define bar(a, ...)  __VA_ARGC__
> > 
> > foo()    // 0
> 
> In C23, I believe it is not specified whether this is an invocation with 0
> arguments, or with 1 empty argument, because both interpretations result in
> the exact same behaviour, but this was unambiguously an invocation with 1
> empty argument in C99 through C17.

I think __VA_ARGC__ should be consistent with __VA_OPT__().

On the other hand, I now realize __VA_OPT__ doesn't work exactly as I expected:

alx@debian:~/tmp$ cat vo.c | nl -ba
     1  #define foo(...)     __LINE__: foo: __VA_OPT__(nonzero args:
__VA_ARGS__)
     2  #define bar(a, ...)  __LINE__: bar: __VA_OPT__(nonzero args:
__VA_ARGS__)
     3  
     4  foo()
     5  foo(x)
     6  foo(,)
     7  
     8  bar(a)
     9  bar(a,)
    10  bar(a,b)
alx@debian:~/tmp$ gcc -E vo.c | grep -v ^# | uniq

4: foo:
5: foo: nonzero args: x
6: foo: nonzero args: ,

8: bar:
9: bar:
10: bar: nonzero args: b

I would have thought that line 9 would expand __VA_OPT__(), as I have
explicitly passed an empty argument as opposed to not passing it.

> 
> If __VA_ARGC__ should return 0 here, then the behaviour of __VA_ARGC__ needs
> to be documented very carefully to be different from the number of variable
> arguments supplied.

Where is the specification of "the number of variable arguments supplied" so
that we can differ from it?

Reply via email to