In article <Dr******************************@earthlink.com> ,
pete <pf*****@mindspring.comwrote:
>Keith Thompson wrote:
>pete <pf*****@mindspring.comwrites:
>>ram kishore wrote:
What is the advantage of pointers to functions?
All function calls are made
with an operand of pointer to function type.
True.
Then the question the OP should have asked is:
What is the advantage of pointers to functions other than those that
result from the implicit conversion of a function name used as the
prefix of a function call?
I recall recently,
in one of the web pages from a URL posted to this newsgroup,
advice that function calls should properly be made this way:
either
function_name();
or
(*function_pointer)();
I wouldn't write function calls differently
for function name versus pointer constructs,
but if I would, I would do it this way:
either
(&function_name)();
or
function_pointer();
The other way doesn't make any sense.
I may be misunderstanding you, and/or the other P above, but seems
to me that although foo() vs (*foo)() etc is a valid discussion,
that it was not the original context of the question, which
was delving into why have functions which can be pointed to at all,
and not delving into stuff like their sytactic equivalences.
That said, as to your point, I probably agree with you and it's
kind of just another set of confusion for most people how this
can all be so:
#include <stdio.h>
void foo()
{
printf("foo\n");
}
void (*pf)();
int main()
{
foo();
(*foo)();
(&foo)();
pf = foo;
pf();
(*pf)();
(&pf)(); // error
}
--
Greg Comeau / 4.3.10.1 with C++0xisms now in beta!
Comeau C/C++ ONLINE ==
http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?