Ben Bacarisse said:
Not really! It's largely habit formed from history. The C I learnt
(K&R C) did not have the automatic conversion of a parameter from
function type to pointer to function type (though it did have that
conversion for array types). Also, a function was called by writing a
function-valued expression before the ()s not a pointer-to-function
expression as now. Hence one had to write:
void foo()
Proc *callme;
{
(*callme)();
}
Whilst I appreciate the simplification of having a pointer-to-function
expression for calling, I've not internalised the conversion in the
parameter list, so I prefer to see it for what it is rather than rely on
the conversion.
You say you don't see any value in using Foo *f. Fair enough. Do you
see any value in preferring Foo f? I had a narrow preference for the
explicit nature of Foo *f and I can't see any reason to drop the * (I am
certain neither of us values fewer keystrokes for the sake of it).
Like you, I originally learned C from K&R, with the (*f)() syntax
for calling through function pointers. I like the new syntax
rule, mostly because calls look cleaner.
I prefer using the 'Foo f' declaration, rather than 'Foo *f', for
several different reasons. Here are some (I'm not claiming
the list is exhaustive just yet):
1. ISO C has eliminated most of the difference between a function
type and a pointer to function type. I think removing this
distinction (which is somewhat artificial) is an improvement in
C, and using 'Foo f' is some movement in that direction.
2. Following the C rule that "declaration mimics use", using 'Foo *f'
seems wrong, because I certainly don't write '*f()', but '(*f)()'
looks like it doesn't match the declaration either.
3. If I need to have a parameter that is a pointer to a pointer
to a function, it seems better to use only one '*' in the
declaration, because those cases will really /need/ the '*';
for example, '*fp = call_back', or '(*fp)()'. Because I write
calls through plain pointer-to-function as 'f()', normally
I would write calls through pointer-to-pointer-to-function
as '(*fp)()', not '(**fp)()'.
4. If given a choice, I would like to indicate somehow that some
variable is a (pointer to) a function, but usually I would do this
using the type name, eg, 'XYZ_callback_f blah', with the '_f'
meaning function (or pointer to function).
Summarizing: I don't find that the '*' adds anything, except
it does add some confusion; conversely, leaving out the '*'
seems to fit better with the new rules for how functions
and pointers-to-function behave, and I've embraced that
direction.
So for what it's worth, those are my thoughts on the matter.