Va_start, vsprintf, Va_end

Source: Internet
Author: User

Va_start,

Function name, the process of reading a variable parameter is actually in the stack, using pointers, traversing the parameter list in the stack segment, from the low address to the high address one by one to read out the contents of the parameter.

vsprintf ()

The arg parameter is in the array. The percentage of the elements of the array that will be inserted into the main string (%) Symbol. This function is executed step-by. In the first% symbol, insert arg1, insert arg2 at the second% symbol, and so on.

/* Function Name: vsprintf

Return value: Returns the length of the generated string normally (except for \ n), and the error condition returns a negative value usage: int vsprintf (char *string, char *format, va_list param); To write a string in param formatted format format NOTE: This function will have a memory overflow condition, it is recommended to use vsnprintf

with macro Va_arg (), Va_start (), and Va_end (), you can pass a variable number of argument operations to a function. A typical example of a variable number of variables is the function printf (). The type va_list is defined in <stdarg.h>.

The following macro prototypes are as follows: Type Va_arg (va_list argptr, type), void Va_end (va_list argptr), void Va_start (Va_list argptr, last_parm); They are all included in the header file <stdarg.h>. Create a general procedure that can get a variable number of arguments: In a function definition, you must have one or more known parameters before the Variadic table, where the right-most is last_parm. When Va_start () is called, the Last_parm name is used as the second argument. Before any variable-length variables are accessed, the variable-pointer argptr must first be initialized with Va_start (). After initializing the argptr, the call to Va_arg () returns the parameter as the parameter type of the next parameter type. Finally, all parameters are taken out and before the function is returned. Va_end () must be called. This ensures proper recovery of the stack.

Va_start, vsprintf, Va_end

Related Keywords:

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.