I was trying to declare a function pointer that points to any function that returns the same type. I omitted the arguments types in the pointer declaration to see what error
void (*pointer)()
explains function pointed have unspecified number of argument. It is not similar to void (*pointer)(void)
. So later when you used two arguments that fits successfully according to definition.
Empty parentheses within a type name means unspecified arguments. Note that this is an obsolescent feature.
C11(ISO/IEC 9899:201x) §6.11.6 Function declarators
The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.
There are couple of things you should know here...
Function declaration:
int myFunction();
Function prototype:
int myFunction(int a, float b);
prototype
is a special kind of declaration that describes the number and the types of function parameters.non-prototype
function declaration doesn't say anything about its parameter.Example:
int myFunction();
This non-prototype
function declaration does not mean that myFunction
takes no arguments. It means that myFunction
take an unspecified number of arguments. The compiler simply turns off argument type checking, number of arguments checking and conversion for myFunction
.
So you can do,
int myFunction(); // The non-prototype signature will match a definition for
// myFunction with any parameter list.
// This is the function definition...
int myFunction(int x, float b, double d)
{
...
}