Frederick Gotham wrote:
Sunil Varma posted:
Is accessing function by it's name faster or accessing it by its
address faster?
Basically you're asking whether
it's faster to access an object directly,
or to ask it via indirection.
Not really.
The only difference is that the name of a function
converts to a constant address in a function call,
whereas a pointer expression may be either a constant or a variable.
In case where there is a difference in speed,
I would expect a constant to be faster than a variable.
(putchar)('A');
should compile the same as
(&putchar)('A');
The only times that a function name doesn't
convert implicitly to a pointer to the function,
is as an operand to the address operator &,
and as an operand of the sizeof operator,
which is why (sizeof function_name) is undefined.
So, it's not a matter of differences in indirection.
--
pete