When a function is declared more than once, all declarations must have compatible type (C11 6.2.7/2). In your code f
is declared twice - the definition also counts as a declaration.
The definition of "compatible function type" is in C11 6.7.6.3/15:
For two function types to be compatible, both shall specify compatible return types. Moreover, the parameter type lists, if both are present, shall agree in the number of parameters and in use of the ellipsis terminator; corresponding parameters shall have compatible types. If one type has a parameter type list and the other type is specified by a function declarator that is not part of a function definition and that contains an empty identifier list, the parameter list shall not have an ellipsis terminator and the type of each parameter shall be compatible with the type that results from the application of the default argument promotions. If one type has a parameter type list and the other type is specified by a function definition that contains a (possibly empty) identifier list, both shall agree in the number of parameters, and the type of each prototype parameter shall be compatible with the type that results from the application of the default argument promotions to the type of the corresponding identifier. (In the determination of type compatibility and of a composite type, each parameter declared with function or array type is taken as having the adjusted type and each parameter declared with qualified type is taken as having the unqualified version of its declared type.)
Therefore void test()
and void test(float)
are incompatible. In other words, after seeing void test();
, any prototype must only use types that are unchanged by the default argument promotions. float
changes to double
under those promotions.
I believe this has always been the case since the first C Standard.