This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: deprecated GNU ## extension used


I would like to submit at least part of the GNU extension for future
standardization.  In particular, I think the ability to give the rest
argument a name will be acceptable to the committee.  I very much
doubt they will accept the magic ##, though.

Therefore, I want the named argument feature kept strictly separate
from the behavior of ##.  I want __VA_ARGS__ to be thought of as the
default name of the rest argument, and I want no behavior to depend on
whether or not the rest argument was given a different name.

There is another way to approach the problem.  The C99 rest argument
must receive at least one actual argument (which may be empty).  The
GNU rest argument is allowed to receive zero actual arguments.  Fine
distinction, yes - perhaps an example would help.

#define error(format, ...) fprintf(stderr, format, __VA_ARGS__)

error("blah blah", )  /* legal C99 until phase 7 */
error("blah blah")    /* illegal C99 at phase 4 */

Therefore, would it be acceptable if the special behavior of ## keyed
off the rest argument receiving zero actual arguments?  So, if you
wrote

#define error(format, args...) \
	fprintf(stderr, "%s:%d " format, file, line, ##args)

error("0", a, b, c)
error("1", )
error("2")

the expansion would be

fprintf (stderr, "%s:%d " "0", file, line,a, b, c)
fprintf (stderr, "%s:%d " "1", file, line,)
fprintf (stderr, "%s:%d " "2", file, line)

and -pedantic would get you a warning for "2" about the rest argument
receiving zero arguments, which satisfies the standard.

Note that "0" will receive a warning about an illegal token paste;
perhaps that should be disabled in this context.  Or perhaps -Wpaste
should not be enabled by -Wall, only -W or -pedantic.  I have no
strong opinion here.

The existing general suppression of -pedantic in system headers should
suffice to prevent the warning for "2".  If it doesn't, come back with
a specific example and an explanation for why exactly you can't do it
some other way.

And if anyone has a problem with ## deleting the previous token
instead of the previous sequence of nonwhitespace characters, kindly
see figure 1.

zw

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]