So Lets say I have a function:
void foo (int i){
cout << "argument is: " << i << endl;
}
And I am passing this function to:
void function1 (void(callback)(int), int arg){
callback(arg);
}
void function2 (void(*callback)(int), int arg){
callback(arg);
}
are these two functions identical? Is there any difference between the two?
They are identical. Parameter having type of a function is converted to pointer to the function type.
The rule is that in a function's parameter list, a parameter declared to have a function type is adjusted to have pointer to function type (similarly, and probably more well-known, a parameter declared to have type "array of
T
" is adjusted to have type "pointer toT
". Redundant parentheses in declarators are allowed, but ignored.Thus, in
The first parameter of those three functions have exactly the same type - "pointer to function of
(int)
returningvoid
".