<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Variadic_macro_in_the_C_preprocessor</id>
	<title>Variadic macro in the C preprocessor - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Variadic_macro_in_the_C_preprocessor"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Variadic_macro_in_the_C_preprocessor&amp;action=history"/>
	<updated>2026-10-26T04:13:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Variadic_macro_in_the_C_preprocessor&amp;diff=5185569&amp;oldid=prev</id>
		<title>imported&gt;Lunovaric at 11:29, 30 October 2025</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Variadic_macro_in_the_C_preprocessor&amp;diff=5185569&amp;oldid=prev"/>
		<updated>2025-10-30T11:29:56Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;http://debianws.lexgopc.com/wiki143/index.php?title=Variadic_macro_in_the_C_preprocessor&amp;amp;diff=5185569&amp;amp;oldid=808132&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>imported&gt;Lunovaric</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Variadic_macro_in_the_C_preprocessor&amp;diff=808132&amp;oldid=prev</id>
		<title>130.88.208.73: __VA_OPT__ should be introduced as being both part of C++20 and C23</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Variadic_macro_in_the_C_preprocessor&amp;diff=808132&amp;oldid=prev"/>
		<updated>2025-06-06T14:07:26Z</updated>

		<summary type="html">&lt;p&gt;__VA_OPT__ should be introduced as being both part of C++20 and C23&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Previous revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 14:07, 6 June 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l18&quot;&gt;Line 18:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;}}&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Both the [[C99]] and [[C++11]] standards require at least one argument, but since [[C++20]] this limitation has been lifted through the {{var|__VA_OPT__}} functional macro. The {{var|__VA_OPT__}} macro is replaced by its argument when arguments are present, and omitted otherwise. Common compilers also permit passing zero arguments before this addition, however.&amp;lt;ref name=&quot;gcc&quot;&amp;gt;[https://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html Variadic Macros – Using the GNU Compiler Collection (GCC)]&amp;lt;/ref&amp;gt;&amp;lt;ref name=&quot;msvc&quot;&amp;gt;[https://msdn.microsoft.com/en-us/library/ms177415(v=vs.140).aspx Variadic Macros (C++)]&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Both the [[C99]] and [[C++11]] standards require at least one argument, but since [[C++20&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;]] and [[C23 (C standard revision)|C23&lt;/ins&gt;]] this limitation has been lifted through the {{var|__VA_OPT__}} functional macro. The {{var|__VA_OPT__}} macro is replaced by its argument when arguments are present, and omitted otherwise. Common compilers also permit passing zero arguments before this addition, however.&amp;lt;ref name=&quot;gcc&quot;&amp;gt;[https://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html Variadic Macros – Using the GNU Compiler Collection (GCC)]&amp;lt;/ref&amp;gt;&amp;lt;ref name=&quot;msvc&quot;&amp;gt;[https://msdn.microsoft.com/en-us/library/ms177415(v=vs.140).aspx Variadic Macros (C++)]&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The C preprocessor rules prevent macro names in the argument of {{var|__VA_OPT__}} from expanding recursively.  It is possible to work around this limitation up to an arbitrary fixed number of recursive expansions, however.&amp;lt;ref name=&amp;quot;recursive-vaopt&amp;quot;&amp;gt;[https://www.scs.stanford.edu/~dm/blog/va-opt.html Recursive macros with C++20 __VA_OPT__]&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The C preprocessor rules prevent macro names in the argument of {{var|__VA_OPT__}} from expanding recursively.  It is possible to work around this limitation up to an arbitrary fixed number of recursive expansions, however.&amp;lt;ref name=&amp;quot;recursive-vaopt&amp;quot;&amp;gt;[https://www.scs.stanford.edu/~dm/blog/va-opt.html Recursive macros with C++20 __VA_OPT__]&amp;lt;/ref&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>130.88.208.73</name></author>
	</entry>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Variadic_macro_in_the_C_preprocessor&amp;diff=423556&amp;oldid=prev</id>
		<title>imported&gt;Cedar101: /* Trailing comma */ &lt;code&gt;</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Variadic_macro_in_the_C_preprocessor&amp;diff=423556&amp;oldid=prev"/>
		<updated>2024-04-09T02:53:15Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Trailing comma: &lt;/span&gt; &amp;lt;code&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Macro taking a varying number of arguments}}&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;variadic macro&amp;#039;&amp;#039;&amp;#039; is a feature of some computer [[programming language]]s, especially the [[C preprocessor]], whereby a [[macro (computer science)|macro]] may be declared to accept a varying number of [[parameter (computer programming)|arguments]]. &lt;br /&gt;
&lt;br /&gt;
Variable-argument macros were introduced in 1999 in the &amp;#039;&amp;#039;ISO/IEC 9899:1999&amp;#039;&amp;#039; ([[C99]]) revision of the [[C (programming language)|C]] language standard, and in 2011 in &amp;#039;&amp;#039;ISO/IEC 14882:2011&amp;#039;&amp;#039; ([[C++11]]) revision of the [[C++]] language standard.&amp;lt;ref&amp;gt;Working draft changes for C99 preprocessor synchronization – http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1653.htm&amp;lt;/ref&amp;gt; Support for variadic macros with no arguments was added in [[C++20]] and will be added in [[C23 (C standard revision)|C23]].&amp;lt;ref&amp;gt;{{cite web|url=https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0306r3.html|title=Comma omission and comma deletion|date=June 18, 2017|access-date=December 24, 2022}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=N3033/&amp;gt;&amp;lt;!-- The first source is the C++ version and the second the C version. They are not duplicates. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Declaration syntax ==&lt;br /&gt;
The declaration syntax is similar to that of [[variadic function]]s: a sequence of three [[full stop]]s &amp;quot;{{var|...}}&amp;quot; is used to indicate that one or more arguments must be passed. During macro expansion each occurrence of the special identifier {{var|__VA_ARGS__}} in the macro replacement list is replaced by the passed arguments.&lt;br /&gt;
&lt;br /&gt;
Additionally, regular macro arguments may be listed before the &amp;lt;code&amp;gt;...&amp;lt;/code&amp;gt;,&amp;lt;ref name=&amp;quot;gcc&amp;quot; /&amp;gt; but regular arguments may not be listed after the &amp;lt;code&amp;gt;...&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
No means is provided to access individual arguments in the variable argument list, nor to find out how many were passed. However, macros can be written to count the number of arguments that have been passed.&amp;lt;ref&amp;gt;{{cite newsgroup&lt;br /&gt;
 |author= Laurent Deniau&lt;br /&gt;
 |title= __VA_NARG__&lt;br /&gt;
 |date= 2006-01-16&lt;br /&gt;
 |newsgroup= comp.std.c&lt;br /&gt;
 |message-id= dqgm2f$ije$1@sunnews.cern.ch&lt;br /&gt;
 |url= http://groups.google.com/group/comp.std.c/browse_thread/thread/77ee8c8f92e4a3fb/346fc464319b1ee5&lt;br /&gt;
}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both the [[C99]] and [[C++11]] standards require at least one argument, but since [[C++20]] this limitation has been lifted through the {{var|__VA_OPT__}} functional macro. The {{var|__VA_OPT__}} macro is replaced by its argument when arguments are present, and omitted otherwise. Common compilers also permit passing zero arguments before this addition, however.&amp;lt;ref name=&amp;quot;gcc&amp;quot;&amp;gt;[https://gcc.gnu.org/onlinedocs/gcc/Variadic-Macros.html Variadic Macros – Using the GNU Compiler Collection (GCC)]&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;msvc&amp;quot;&amp;gt;[https://msdn.microsoft.com/en-us/library/ms177415(v=vs.140).aspx Variadic Macros (C++)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The C preprocessor rules prevent macro names in the argument of {{var|__VA_OPT__}} from expanding recursively.  It is possible to work around this limitation up to an arbitrary fixed number of recursive expansions, however.&amp;lt;ref name=&amp;quot;recursive-vaopt&amp;quot;&amp;gt;[https://www.scs.stanford.edu/~dm/blog/va-opt.html Recursive macros with C++20 __VA_OPT__]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Support ==&lt;br /&gt;
Several [[compiler]]s support variable-argument macros when compiling C and C++ code: the [[GNU Compiler Collection]] 3.0,&amp;lt;ref name=&amp;quot;gcc&amp;quot; /&amp;gt; [[Clang]] (all versions),&amp;lt;ref&amp;gt;Clang source code change that mentions __VA_ARGS__ support (2006-07-29), note that Clang was open-sourced in 2007. http://llvm.org/viewvc/llvm-project?view=revision&amp;amp;revision=38770&amp;lt;/ref&amp;gt; [[Visual Studio 2005]],&amp;lt;ref name=&amp;quot;msvc&amp;quot; /&amp;gt; [[C++Builder]] 2006, and [[Oracle Solaris Studio]] (formerly Sun Studio) Forte Developer 6 update 2 (C++ version 5.3).&amp;lt;ref&amp;gt;Sun Studio feature comparison – http://developers.sun.com/sunstudio/support/CCcompare.html&amp;lt;/ref&amp;gt;  GCC also supports such macros when compiling [[Objective-C]].&lt;br /&gt;
&lt;br /&gt;
Support for the {{var|__VA_OPT__}} macro to support zero arguments has been added in [[GNU Compiler Collection]] 8,&amp;lt;ref&amp;gt;{{cite web|url=https://gcc.gnu.org/projects/cxx-status.html#cxx2a|title=C++2a Support in GCC|access-date=June 14, 2018}}&amp;lt;/ref&amp;gt; [[Clang]] 6,&amp;lt;ref&amp;gt;{{cite web|url=https://clang.llvm.org/cxx_status.html|title=C++ Support in Clang|access-date=June 14, 2018}}&amp;lt;/ref&amp;gt; and [[Visual Studio 2019]].&amp;lt;ref&amp;gt;{{cite web|url=https://docs.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview|title=MSVC new preprocessor overview|date=September 10, 2020|access-date=December 8, 2020}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
If a &amp;lt;code&amp;gt;[[printf]]&amp;lt;/code&amp;gt;-like [[subroutine|function]] {{code|dbgprintf()}} were desired, which would take the file and line number from which it was called as arguments, the following solution applies.&lt;br /&gt;
&amp;lt;!-- Don&amp;#039;t change the example back to dprintf; it is a POSIX function: http://pubs.opengroup.org/onlinepubs/9699919799/functions/dprintf.html --&amp;gt;&lt;br /&gt;
{{olist&lt;br /&gt;
|Our implemented function&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
void realdbgprintf (const char *SourceFilename,&lt;br /&gt;
                    int SourceLineno,&lt;br /&gt;
                    const char *CFormatString,&lt;br /&gt;
                    ...);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| &amp;lt;p&amp;gt;Due to limitations of the variadic macro support in C++11 the following&lt;br /&gt;
straightforward solution can fail and should thus be avoided:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
   #define dbgprintf(cformat, ...) \&lt;br /&gt;
     realdbgprintf (__FILE__, __LINE__, cformat, __VA_ARGS__)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The reason is that&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
   dbgprintf(&amp;quot;Hallo&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
gets expanded to&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
   realdbgprintf (__FILE__, __LINE__, &amp;quot;Hallo&amp;quot;, )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
where the comma before the closing brace will result in a syntax error.&lt;br /&gt;
| GNU C++ supports a non-portable extension which solves this.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
   #define dbgprintf(cformat, ...) \&lt;br /&gt;
     realdbgprintf (__FILE__, __LINE__, cformat, ##__VA_ARGS__)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| C++20 eventually supports the following syntax.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
   #define dbgprintf(cformat, ...) \&lt;br /&gt;
     realdbgprintf (__FILE__, __LINE__, cformat __VA_OPT__(,) __VA_ARGS__)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| By using the &amp;#039;cformat&amp;#039; string as part of the variadic arguments we can&lt;br /&gt;
circumvent the abovementioned incompatibilities.  This is tricky but&lt;br /&gt;
portable.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define dbgprintf(...) realdbgprintf (__FILE__, __LINE__, __VA_ARGS__)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
{{code|dbgprintf()}} could then be called as&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
dbgprintf (&amp;quot;Hello, world&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which expands to&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
realdbgprintf (__FILE__, __LINE__, &amp;quot;Hello, world&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another example is&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
dbgprintf(&amp;quot;%d + %d = %d&amp;quot;, 2, 2, 5);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which expands to&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
realdbgprintf(__FILE__, __LINE__, &amp;quot;%d + %d = %d&amp;quot;, 2, 2, 5);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Without variadic macros, writing wrappers to &amp;lt;code&amp;gt;[[printf]]&amp;lt;/code&amp;gt; is not directly possible.  The standard workaround is to use the [[Stdarg.h|stdargs]] functionality of C/C++, and have the function call &amp;lt;code&amp;gt;[[vprintf]]&amp;lt;/code&amp;gt; instead.&lt;br /&gt;
&lt;br /&gt;
== Trailing comma ==&lt;br /&gt;
There is a portability issue with generating a trailing comma with empty args for variadic macros in [[C99]]. Some compilers (e.g., Visual Studio when not using the new standard-conformant preprocessor&amp;lt;ref name=&amp;quot;msvc&amp;quot; /&amp;gt;) will silently eliminate the trailing comma. Other compilers (e.g.: GCC&amp;lt;ref name=&amp;quot;gcc&amp;quot; /&amp;gt;) support putting {{code|##}} in front of &amp;lt;code&amp;gt;{{var|__VA_ARGS__}}&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
# define MYLOG(FormatLiteral, ...)  fprintf (stderr, &amp;quot;%s(%u): &amp;quot; FormatLiteral &amp;quot;\n&amp;quot;, __FILE__, __LINE__, __VA_ARGS__)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
The following application works&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
MYLOG(&amp;quot;Too many balloons %u&amp;quot;, 42);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which expands to&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
fprintf (stderr, &amp;quot;%s(%u): &amp;quot; &amp;quot;Too many balloons %u&amp;quot; &amp;quot;\n&amp;quot;, __FILE__, __LINE__, 42);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which is equivalent to&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
fprintf (stderr, &amp;quot;%s(%u): Too many balloons %u\n&amp;quot;, __FILE__, __LINE__, 42);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
But look at this application:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
MYLOG(&amp;quot;Attention!&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which expands to&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
fprintf (stderr, &amp;quot;%s(%u): &amp;quot; &amp;quot;Attention!&amp;quot; &amp;quot;\n&amp;quot;, __FILE__, __LINE__, );&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which generates a syntax error with GCC.&lt;br /&gt;
&lt;br /&gt;
GCC supports the following (non-portable) extension:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
# define MYLOG(FormatLiteral, ...)  fprintf (stderr, &amp;quot;%s(%u): &amp;quot; FormatLiteral &amp;quot;\n&amp;quot;, __FILE__, __LINE__, ##__VA_ARGS__)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which removes the trailing comma when &amp;lt;code&amp;gt;{{var|__VA_ARGS__}}&amp;lt;/code&amp;gt; is empty.&lt;br /&gt;
&lt;br /&gt;
[[C23 (C standard revision)|C23]] solves this problem by introducing &amp;lt;code&amp;gt;{{var|__VA_OPT__}}&amp;lt;/code&amp;gt; like C++.&amp;lt;ref name=N3033&amp;gt;{{cite web|url=https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3033.htm|title=WG14 - N3033 : Comma omission and comma deletion|date=2022-07-20}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Alternatives ==&lt;br /&gt;
Before the existence of variable-arguments in C99, it was quite common to use doubly nested parentheses to exploit the variable number of arguments that could be supplied to the {{code|printf()}} function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
#define dbgprintf(x) realdbgprintf x&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{code|dbgprintf()}} could then be called as:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
dbgprintf ((&amp;quot;Hello, world %d&amp;quot;, 27));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
which expands to:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;c&amp;quot;&amp;gt;&lt;br /&gt;
realdbgprintf (&amp;quot;Hello, world %d&amp;quot;, 27);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Variadic function]]&lt;br /&gt;
* [[Variadic template]]&lt;br /&gt;
&lt;br /&gt;
[[Category:C (programming language)]]&lt;br /&gt;
[[Category:C++]]&lt;br /&gt;
&lt;br /&gt;
[[ja:可変長引数]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Cedar101</name></author>
	</entry>
</feed>