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."
The above is the detailed content of Do All Variadic Functions Promote `float` Arguments to `double`?. For more information, please follow other related articles on the PHP Chinese website!