Calls with a variable number of arguments

xiaoxiao2021-03-06  120

From: C Language Reference (Visual C .NET)

A partial parameter list can be terminated by the ellipsis notation, a comma followed by three periods (, ...), to indicate that there may be more arguments passed to the function, but no more information is given about them. Type checking is not performed on such arguments. At least one parameter must precede the ellipsis notation and the ellipsis notation must be the last token in the parameter list. Without the ellipsis notation, the behavior of a function is undefined if it receives parameters in addition to those declared In the parameter list.

To call a function with a variable number of arguments, simply specify any number of arguments in the function call. An example is the printf function from the C run-time library. The function call must include one argument for each type name declared in the Parameter List or The List of Argument Types.

All the arguments specified in the function call are placed on the stack unless the __fastcall calling convention is specified. The number of parameters declared for the function determines how many of the arguments are taken from the stack and assigned to the parameters. You are responsible for retrieving any additional arguments from the stack and for determining how many arguments are present The STDARG.H file contains ANSI-style macros for accessing arguments of functions which take a variable number of arguments Also, the XENIX -..? style macros in VARARGS. H Are STILL Supported.

THIS SAMPLE DECLATION IS for a Function That Calls a Variable Number of Arguments:

Int average (int first, ...); microsoft specific->

To maintain compatibility with previous versions of Microsoft C, a Microsoft extension to the ANSI C standard allows a comma without trailing periods (,) at the end of the list of parameters to indicate a variable number of arguments. However, it is recommended that code Be Changd to Incorporate the Ellipsis Notation.end Microsoft Specific

转载请注明原文地址:https://www.9cbs.com/read-125788.html

New Post(0)