Notes for variable parameter lists

Source: Internet
Author: User

Using the macros va_arg, va_end, and va_start, You can input variable parameters in the function. Such as printf and sprintf.

When I wrote a variable parameter list myself today, I found several notes.

 

The excerpt is as follows:

Here: http://www.cppblog.com/ownwaterloo/archive/2009/04/21/unacceptable_type_in_va_arg.html


Simply put, we use va_arg
(AP
, Type
) When a parameter is retrieved,
Type
Absolutely
The pair cannot be

The following types:
--Char

, Signed
Char

, Unsigned
Char


--Short

, Unsigned
Short


-- Signed
Short

,Short

Int
, Signed
Short

Int
, Unsigned
Short

Int

--Float

A simple reason is:
--No caller
Yes

To my_printf
Transfer
The precedingActual Parameters
.

When calling a function without a prototype declaration in C language:
The caller willEach
Run the "Default actual parameters" command.Upgrade
(Default argumentPromotions
)".

In addition, the variable length parameter listExceeds the last
YesType Declaration Form Parameter
AfterEach actual Parameter
.
The improvement is as follows:
-- The actual parameter of float type will be upgraded to double
-- The actual parameters of char, short, and corresponding signed and unsigned types are upgraded to int
-- If int cannot store the original value, it is upgraded to unsigned Int.

Then, the callerAfter Upgrade
ParametersTransfer
To the caller.
Therefore, my_printf isCannot receive
The actual parameters of the preceding type.

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.