Pointers to functions
Greg Comeau
comeau at ditka.Chicago.COM
Fri May 17 15:17:58 AEST 1991
In article <AJ3U.91May14140642 at wilbury.cs.virginia.edu> aj3u at wilbury.cs.virginia.edu (Asim Jalis) writes:
>pf = hello; and pf = &hello;
>The definitions for pf and hello are as follows:
>void (*pf)(); // pointer to a function
>void hello() { printf("Hello World\n"); }
>I used the two different forms of assignments and got the same output.
>Is there a difference between them?
There is a difference even though they both end up at the same.
In 'pf = hello;', the function name expression is implicitly converted into
a pointer to a function of the appropriate type (a void(*)()) when in this
context.
With 'pf = &hello;', since the operand of & is a function, it is a pointer
to a function of the appropriate type. It does not become a pointer to a
pointer to a function.
The C++ style is to use the & form.
- Greg
--
Comeau Computing, 91-34 120th Street, Richmond Hill, NY, 11418
Producers of Comeau C++ 2.1
Here:attmail.com!csanta!comeau / BIX:comeau / CIS:72331,3421
Voice:718-945-0009 / Fax:718-441-2310
More information about the Comp.lang.c
mailing list