Chapter 5: Keyword Summary

C99 Variable Argument Lists

C99 adds to the preprocessor the ability to create macros that take a variable number of arguments. This is indicated by an ellipsis (. . .) in the definition of the macro. The built-in preprocessing identifier _ _VA_ARGS_ _ determines where the arguments will be substituted. For example, given this definition,

#define MyMax(...) max(_ _VA_ARGS_ _)

this statement

MyMax(a, b);

is transformed into

max(a, b);

There can be other arguments prior to the variable ones. For example, given

#define compare(compfunc, ...) compfunc(_ _VA_ARGS_ _)

this statement

compare(strcmp, "one", "two");

is transformed into

strcmp("one", "two");

As the example shows, _ _VA_ARGS_ _ is replaced by all of the remaining arguments.




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net