Is it purely style that you can declare a function-reference parameter like,
int g ( int (*f)(int,int) ) {
Or
int g ( int f(int,int) ) {
In my limited experience with C, I've never seen the prototype-method.
I suppose it is style, but the explicit pointer to function notation aligns with ancient practice and with the way the compiler interprets the code.
The C11*
standard says in §6.7.6.3 Function declarators (including prototypes) ¶8:
¶8 A declaration of a parameter as "function returning type" shall be adjusted to "pointer to function returning type", as in 6.3.2.1.
And §6.3.2.1 Lvalues, arrays and function designators ¶4 says:
¶4 A function designator is an expression that has function type. Except when it is the operand of the
sizeof
operator, the_Alignof
operator,65) or the unary&
operator, a function designator with type "function returning type" is converted to an expression that has type "pointer to function returning type".65) Because this conversion does not occur, the operand of the
sizeof
or_Alignof
operator remains a function designator and violates the constraints in 6.5.3.4.
Using the pointer notation, therefore, shows explicitly what the compiler will do anyway. (I still usually invoke explicit pointers to functions using the (*function_ptr)(arg1, …, argN)
notation, even though function_ptr(arg1, …, argN)
also works.)
*
The C18 standard is current, but there isn't a convenient online HTML version of it available as yet. Mostly, the two are very similar. As it happens, §6.3.2.1 ¶4 is one paragraph with a difference — the C18 version doesn't mention _Alignof
.