Using void (*)() pointers for other functions

In this particular case, the calls are legal.

Section 6.7.6.3p15 of the C standard spells out what makes two function type compatible (relevant part in bold):

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.)

So you have a typedef with type:

void()

And functions with type:

void(void)
void(double)

The two function definitions don’t use ellipsis (...) so that satisfies the fist condition. For the second condition, let’s look at what the default argument promotions are. Those are specified in section 6.5.2.2p6:

If the expression that denotes the called function has a
type that does not include a prototype, the integer promotions
are performed on each argument, and arguments that have type
float are promoted to double. These are called the default
argument promotions
.

The first function has no arguments, so it is compatible. The second function has a single double argument, which matches the default argument promotions, so it is also compatible.

To give some more examples, the following functions would also be compatible:

void f1(long);
void f2(int);

But these would not:

void f3(float);
void f4(char);
void f5(short);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)