Whole document tree
4.15 Macros with Variable Numbers of ArgumentsIn GNU C, a macro can accept a variable number of arguments, much as a function can. The syntax for defining the macro looks much like that used for a function. Here is an example:
Here
Note that the comma after the string constant comes from the definition
of
The reason for using `##' is to handle the case when
which is invalid C syntax. `##' gets rid of the comma, so we get the following instead:
This is a special feature of the GNU C preprocessor: `##' before a rest argument that is empty discards the preceding sequence of non-whitespace characters from the macro definition. (If another macro argument precedes, none of it is discarded.) It might be better to discard the last preprocessor token instead of the last preceding sequence of non-whitespace characters; in fact, we may someday change this feature to do so. We advise you to write the macro definition so that the preceding sequence of non-whitespace characters is just a single token, so that the meaning will not change if we change the definition of this feature.
This document was generated by root on January, 30 2002 using texi2html |