When a function is declared more than once, all declarations must be of a compatible type (C11 6.2.7 / 2). In your code, f
declared twice - the definition is also considered a declaration.
The definition of "compatible function type" is given in C11 6.7.6.3/15:
For two types of functions that must be compatible, both must indicate compatible return types. Moreover, lists of parameter types, if they are both present, must agree on the number of parameters and use a terminator with an ellipsis; corresponding parameters must have compatible types. If one type has a list of parameter types, and the other type is specified by the function declarator, which is not part of the function definition and contains an empty list of identifiers, the parameter list should not have an ellipsis terminator, and each parameter type must be compatible with the type that arises due to default promotions. If one type has a list of parameter types, and another type is determined by the definition of a function that contains a (possibly empty) list of identifiers, both are consistent in the number of parameters, and the type of each prototype parameter must be compatible with the type that arises from the application of the promo default arguments to the type of the corresponding identifier. (When determining type and composite type compatibility, each parameter declared using a function or array type is accepted as having an adjusted type, and each parameter declared using a qualified type is accepted as having an unqualified version of its declared type.)
Therefore, void test()
and void test(float)
are incompatible. In other words, after viewing void test();
Any prototype should use only those types that do not change by default. float
changes to double
under these promotions.
I believe this has always been the case with the first standard C.
source share