A variadic macro is a feature of some computer programming languages, especially the C preprocessor, whereby a macro may be declared to accept a varying number of arguments.
Variable-argument macros were introduced in 1999 in the ISO/IEC 9899:1999 (C99) revision of the C language standard, and in 2011 in ISO/IEC 14882:2011 (C++11) revision of the C++ language standard. Support for variadic macros with no arguments was added in C++20 and will be added in C23.
The declaration syntax is similar to that of variadic functions: a sequence of three full stops "" is used to indicate that one or more arguments must be passed. During macro expansion each occurrence of the special identifier in the macro replacement list is replaced by the passed arguments.
Additionally, regular macro arguments may be listed before the ..., but regular arguments may not be listed after the ....
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.
Both the C99 and C++11 standards require at least one argument, but since C++20 this limitation has been lifted through the functional macro. The macro is replaced by its argument when arguments are present, and omitted otherwise. Common compilers also permit passing zero arguments before this addition, however.
The C preprocessor rules prevent macro names in the argument of from expanding recursively. It is possible to work around this limitation up to an arbitrary fixed number of recursive expansions, however.
Several compilers support variable-argument macros when compiling C and C++ code: the GNU Compiler Collection 3.0, Clang (all versions), Visual Studio 2005, C++Builder 2006, and Oracle Solaris Studio (formerly Sun Studio) Forte Developer 6 update 2 (C++ version 5.3). GCC also supports such macros when compiling Objective-C.
Support for the macro to support zero arguments has been added in GNU Compiler Collection 8, Clang 6, and Visual Studio 2019.
This page is automatically generated and may contain information that is not correct, complete, up-to-date, or relevant to your search query. The same applies to every other page on this website. Please make sure to verify the information with EPFL's official sources.
The C preprocessor is the macro preprocessor for several computer programming languages, such as C, Objective-C, C++, and a variety of Fortran languages. The preprocessor provides inclusion of , macro expansions, conditional compilation, and line control. In many C implementations, it is a separate program invoked by the compiler as the first part of translation. The language of preprocessor directives is only weakly related to the grammar of C, and so is sometimes used to process other kinds of .
A recent study pointed out that macroscopic dark matter (macros) traversing through the Earth’s atmosphere can give rise to hot and ionized channels similar to those associated with lightning leaders. The authors of the study investigated the possibility t ...
2021
, ,
In metaprogramming, code generation and code analysis are complementary. Traditionally, principled metaprogramming extensions for programming languages, like MetaML and BER MetaOCaml, offer strong foundations for code generation but lack equivalent support ...
For any programming language that supports macros and has multiple implementations (each with different AST definitions), there is a common problem: how to make macros that operate on ASTs portable among different compiler implementations? Implementing por ...