Http://dev.yesky.com/424/2110924.shtml
Introduction
C/C ++ has a feature different from other languages, that is, it supports variable parameters. Typical functions such as printf and scanf can accept a certain number of parameters. For example:
Default variable parameter constant parameter variable parameter input and output parameter 7.4.4 for external parameters in swift language set default value for external parameterDevelopers can also set default values for external parameters. At
C/C ++ supports variable parameter functions, that is, the function parameters are uncertain.
I. Why do I need a Variable Parameter Function?
Generally, when programming, the number of formal parameters in the function is usually determined, and
Http://hi.baidu.com/ldlmeiufvkgmtzr/item/8074dd1349b739fddceecafa
I. Why do I need a Variable Parameter Function?
Generally, when programming, the number of formal parameters in the function is usually determined, and all actual parameters
I. Why do I need a Variable Parameter Function?
Generally, when programming, the number of formal parameters in the function is usually determined, and all actual parameters corresponding to the formal parameters should be given in sequence
Write a simple variable parameter C function
Next we will discuss how to write a simple variable parameter C function.C functions use the following Macros in the program:Void va_start (va_list arg_ptr, prev_param );
Type va_arg (va_list arg_ptr,
In/*java, the parameter list is not fixed, but the parameter type is the same, and when used, the formal parameter variable is the reference of the array type */public class Appenter{public static void Main (string[] args) Throws
Introduction to Variable Parameter ellipsis, variable parameter ellipsis
Introduction to Variable Parameter ellipsis
C allows you to define the number of parameters and functions with uncertain types. For example, the standard function printf in C
Today the calculation method This class feel bored extremely, so took out C + + programming way to look at. Inadvertently saw the #include va_list,va_start,va_end and other things, I do not know how to use, so I want to solve.Back to the dorm after
(1) write a simple variable parameter C function
Next we will discuss how to write a simple variable parameter C function.C functions use the following Macros in the program:Void va_start (va_list arg_ptr, prev_param );
Type va_arg (va_list arg_ptr,
I. Variable Parameter Function Definition Methods
Note: The original Article of this section is excerpted from the Internet. I have edited and expanded it as necessary. I am sorry and grateful for the fact that the original author has not found
C language uses the va_list, va_start, va_end, and va_arg macros to define variable parameter functions, va_listva_arg
Before defining a function with variable parameters, let's first understand the transfer principle of the function parameters:
1.
In C programming we will encounter some functions with variable number of parameters, such as printf ()This function, which is defined as this:int printf (const char* format, ...);In addition to having a parameter format fixed, the number and type
Implementation of Variable Parameter List
When learning C language, do you think that printf is a God-like function like me? He can accept different numbers and different types of parameters. How does he implement it?
Let's take a look at its source
Va_list is a group of macros that solve the argument problem in the C language he has so many members:1) va_list type variable:#ifdef _m_alphatypedef struct{char* A0; /*pointertofirsthomedintegerargument*/int offset; /*byteoffsetofnextparameter*/}va_
Let's briefly summarize the basic usage:1 voidSumintN, ...)2 {3Va_list arg_ptr = NULL;//Request a pointer4 5Va_start (arg_ptr, N);//set the pointer to point to6 7Va_arg (Arg_ptr,int);//Loop takes parameters out one by one8 9Va_end
Va_list is a group of macros that solve the argument problem in the C language he has so many members:1) va_list type variable:#ifdef _m_alphatypedef struct{char* A0; /*pointertofirsthomedintegerargument*/int offset; /*byteoffsetofnextparameter*/}va_
Variable parameter: variable parameter.Format: Method name (parameter type ... Name of the parameter)When a function is defined with a mutable parameter, the function can pass in multiple actual arguments of the type at a time when it is called.The
Compiler built-in macros:
First, we will introduce several built-in macro definitions of the compiler. These macro definitions can not only help us write cross-platform source code, but also help us output useful debugging information flexibly.
The
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.