Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 31 Mar 2015 15:40:04 -0500 Return-Path: Sender: std-cpp-request@vandevoorde.com Approved: james.dennett@gmail.com Message-ID: <551990B5.3000601@verizon.net> Newsgroups: comp.std.c++ From: James Kuyper Subject: Re: Macro replacement interpretation Organization: Self References: Content-Type: text/plain; charset=utf-8 X-Original-Date: Mon, 30 Mar 2015 14:06:45 -0400 X-Submission-Address: std-cpp-submit@vandevoorde.com Date: Tue, 31 Mar 2015 15:38:38 CST Lines: 73 X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-mG5wdkieqXpk/Clse+We4Ohx8QNyFWxLtg+6/FpeQxOkCYdz7NZuFcaw4SZ69EB7f/PltlZfUcgekb5!SzyqXKxlvpo5fxucGby7rUqHzQYSIw+CTUgtsXGHKMkh2enTcT4wbA== X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4126 Xref: csiph.com comp.std.c++:749 On 03/30/2015 02:21 PM, Edward Diener wrote: > > On 3/29/2015 5:01 AM, Jakob Bohm wrote: > >> >> On 26/03/2015 19:09, Edward Diener wrote: >> >> >>> Section 16.3 paragraph 4 of the C++11 standard reads: ... >>> equal the number of parameters in the macro definition. Otherwise, there >>> shall be more arguments in the invocation than there are parameters in >>> th= ... >> If that quotation is the complete specification, it seems that there is >> no syntax to define a macro accepting 0 or more parameters ... >> , and no >> syntax to name the last mandatory parameter. >> > > I do not know what is meant by this. Why would one need a "name" for the > last mandatory parameter ? For any given macro the name of the last > mandatory parameter is evident. "Otherwise, there shall be more arguments in the invocation than there are parameters in the macro definition." In this context, "otherwise refers to function-like macros with "..." in the parameter list. Note the "shall" - the behavior is undefined unless there is at least one argument that has no corresponding named parameter. That first extra argument is therefore mandatory (at least, if you wish to avoid undefined behavior); it is also the last mandatory argument (at least as far as C is concerned - the expansion of the function-like macro itself may impose additional requirements). >> Thus it might be >> cumbersome to use the standard syntax to implement >> int printf(const char *fmt, ...) as a macro that invokes >> int fprintf_private(FILE *f, const char *fmt, size_t fmtlen, ...). >> > > If the ... might have 0 parameters then the macro is: > > int printf(...) I'm not sure what the above is supposed to be. You call it a macro, yet there's an 'int' rather than a #define at the front, which makes it appear to be a declaration. The declaration for printf is int printf(const char * restrict format, ...); In order for printf() to be defined as macro that calls fprintf_private() while allowing it be called with only a format string (as is legal), it would have to look something like this: // Remove any pre-existing #define of printf() by the implementation. #undef printf #define printf(...) fprintf_private(stdout, \\ count_va_args(#__VA_ARGS__), __VA_ARGS__) If it weren't done that way, printf("Hello World!") would violate 16.3p4, so fmt cannot be passed as the second argument of fprintf_private(), as originally specified by Jakob Bohm. It would have to be passed along with the variable part of the argument list. -- [ comp.std.c++ is moderated. To submit articles, try posting with your ] [ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.comeaucomputing.com/csc/faq.html ]