Promotion of Float Argument to Double in Variadic Functions
In a previous discussion, it was noted that printf() promotes a float argument to a double before accepting it. This raises the question: do all variadic functions perform this promotion?
Variadic Argument Promotion
Yes, according to both the C99 and C standards, float arguments passed to variadic functions are promoted to double.
Standard Specifications
cppreference on Variadic Function Conversions
cppreference provides a summary of the default conversions for variadic functions in C :
Origin of Promotion
This promotion was introduced in C for compatibility with the K&R C standard, despite its potential drawbacks. As the C Rationale states:
"For compatibility with past practice, all argument promotions occur as described in K&R in the absence of a prototype declaration, including the not always desirable promotion of float to double."
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3