I noticed that
float f;
[..]
printf("%i\n", f);
is not reasonable
but
printf("%i\n", (int)f);
is
but also
int func(float f) {
return f;
}
is ok on
printf("%i\n", func(f));
Is that conversion/casting that is being done by the return process or the function supported by the standard, or does it ideally need
int func(float f) {
return (int) f;
}
?
The conversion is standard. The relevant part of the ISO C99 standard is in section 6.8.6.4, paragraph 3:
So it’s implicitly converted, in the same way that it is in this assignment:
The allowed conversions are:
arithmetic type;
compatible with the type of the expression;
void, and the return type has all the qualifiers of the expression type;_Booland the expression is a pointer.(Your example matches the first one – both
intandfloatare arithmetic types)