About the variable parameter list

Source: Internet
Author: User

A variable argument list allows a function to receive different numbers of arguments at different times, and the most typical example is printf ().

Now let's take a look at how to implement a printf function in the simplest way.

First, the header file:

#include <stdarg.h>

After the Stdarg.h header file is included, we can use the following macros:

Va_start, Va_end

There are also data types:

Va_list

Specifically implemented as follows:

1 void my_printf (char *fmt, ...)
2 {
3 va_list list;
4 Va_start (list, FMT);
5 vprintf (FMT, list);
6 va_end (list);
7}

Va_start is used to initialize so that the list points to the first argument after FMT.

Va_end is called when the use is complete.


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.