Reputation: 13
When I using variable parameters, it works well with int and double, but when it comes to float, error happens.
Here is the code.
void vaParamTest(int a, ...)
{
va_list ap;
va_start(ap, a);
for (int i = 0; i < a; i++)
printf("%f\t", va_arg(ap, float));
putchar('\n');
va_end(ap);
}
I pass parameters like this.
vaParamTest(3, 3.5f, 8.3f, 5.1f);
Upvotes: 0
Views: 171
Reputation: 477308
Variables that are passes as variadic function arguments are default-promoted, which makes all float
s into double
s. You can never have a float
argument (just like you can never have a char
argument). In printf
, %f
always means double
.
Upvotes: 9