typedef int (xxx)(int yyy);
seems to define a function pointer named xxx
which points to a function with a integer parameter yyy
.
But I can't understand that syntax...Could any one give a good explanation?
I find typedef int xxx(int yyy);
still works. Any difference between them?
This defines a function type, not a function pointer type.
The pattern with typedef
is that it modifies any declaration such that instead of declaring an object, it declares an alias to the type the object would have.
This is perfectly valid:
typedef int (xxx)(int yyy); // Note, yyy is just an unused identifier.
// The parens around xxx are also optional and unused.
xxx func; // Declare a function
int func( int arg ) { // Define the function
return arg;
}
The C and C++ languages specifically, and mercifully, disallow use of a typedef
name as the entire type in a function definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With