<stdarg.h>
• stdarg.h is a header in the C standard library of the C programming language that allows functions to accept an indefinite number of arguments. C++ provides this functionality in the header cstdarg; the C header, though permitted, is deprecated in C++.
• The contents of stdarg.h are typically used in variadic functions, though they may be used in other functions (for example, vprintf) called by variadic functions.
Declaring variadic functions
Variadic functions are functions which may take a variable number of arguments and are declared with an ellipsis in place of the last parameter. An example of such a function is printf. A typical declaration is
int check(int a, double b, ...);
Variadic functions must have at least one named parameter, so, for instance,
char *wrong(...);
is not allowed in C. (In C++, such a declaration is permitted, but not very useful.) In C, a comma must precede the ellipsis; in C++, it is optional.
Defining variadic functions
The same syntax is used in a definition:
long func(char, double, int, ...);
long func(char a, double b, int c, ...)
{
/* ... */
}
An ellipsis may also appear in old-style function definitions:
long func();
long func(a, b, c, ...)
char a;
double b;
{
/* ... */
}
• stdarg.h is a header in the C standard library of the C programming language that allows functions to accept an indefinite number of arguments. C++ provides this functionality in the header cstdarg; the C header, though permitted, is deprecated in C++.
• The contents of stdarg.h are typically used in variadic functions, though they may be used in other functions (for example, vprintf) called by variadic functions.
Declaring variadic functions
Variadic functions are functions which may take a variable number of arguments and are declared with an ellipsis in place of the last parameter. An example of such a function is printf. A typical declaration is
int check(int a, double b, ...);
Variadic functions must have at least one named parameter, so, for instance,
char *wrong(...);
is not allowed in C. (In C++, such a declaration is permitted, but not very useful.) In C, a comma must precede the ellipsis; in C++, it is optional.
Defining variadic functions
The same syntax is used in a definition:
long func(char, double, int, ...);
long func(char a, double b, int c, ...)
{
/* ... */
}
An ellipsis may also appear in old-style function definitions:
long func();
long func(a, b, c, ...)
char a;
double b;
{
/* ... */
}
0 comments:
Post a Comment