Ben Bacarisse said:
Also true.
Not true or at least a little misleading. In standard C (i.e. after
K&R C) a function called though a pointer.
Ok, it was you who said this was old code a couple posts earlier, yes? So,
why are you now describing in terms of standard C? ... And, using that to
declare "misleading"?
I.e. the call operator
does the dereference.
False.
There is no "call operator" in any generation of C or C specification. So,
*it* can't possibly "do the dereference". Who's misleading who here?
But, let's say a "call operator" did exist. Even so, that's still false.
The "call operator" wouldn't be able to determine if it was trying to call a
function using function type or a function pointer. And, therefore the
operator wouldn't be able to determine when to and when not to dereference.
I think you mean that the function is called once the function pointer is
dereferenced. Isn't that exactly what I said? (No? Close enough? * is the
last syntactical element...) FYI, it's not a cast to a function, see the *
between the int and arg-list? That means function pointer instead of a
function.
There is a cast to a function pointer and a dereference (via indirection
operator) of said pointer. Once dereferenced, the function is called.
There are only a few things you can with a function, such as call it or
convert to function pointer.
No * is needed though it does no harm.
Yes, for ANSI C or later, the syntax optional. It's not implicit. But, the
functionality is required. Optional syntax doesn't mean my statement above
is misleading. The description describes what occurs. In this case, the
code's syntax accurately does so also. We have a function pointer and not a
function. That function pointer must still be dereferenced to a function
type so that the function can be called. The compiler implements the
indirection operator behind the scenes for the optional syntax. Once the
function pointer is dereferenced, then the function can be called. The
dereferencing is not implicit because the syntax for a function call, for
ANSI C or later, is for calling either a function or a function via a
function pointer. The compiler needs to dereference sometimes, but not
always. It must "know" which is which.
The *
turns the pointer into a function
Yes, that's called dereferencing a pointer. It's done by * - the
indirection operator. Once it's a function, the function is called.
and that function is automatically
turned back into a pointer for the call to happen.
Feel free to cite... (any C spec. or H&S will do.) I believe this to be
dependent on the implementation.
Rod Pemberton