B
BartC
Ben Bacarisse said:I don't think you've expressed this very well. The () "operator" of a
function call does not need to dereference anything (though it may well
do so). The point is that F and F() are different in C but without ()s
in a call you need a way to distinguish between a call and a reference
to the function (which becomes a pointer, just like most mentions of
arrays do). I.e.
x = F;
is ambiguous -- it could be a call or an assignment of a function
pointer.
OK. I'm used to a rather difference point of view, where functions and
function pointers are distinct.
So if a function name F is used in an expression, it will be called. If a
function pointer P is used in an expression, you just get the pointer value,
unless explicitly dereferenced, say using *P. Then you get a function, and
that will then be called.
This is different from C where both F() and P() result in a call, and both F
and P result in a function pointer. Dereferencing is not needed to elevate P
to the same status as F. Neither is 'referencing' (&F) needed to obtain
function addresses. That's quite a neat model.
But get rid of (), and that model no longer works, and you might end up
needing that dereferencing:
F Call F (because F is a function)
&F Address of F
P Address of some function
*P Call that function (after dereferencing, because *P is a function)