pointers to functions
John Mundt
john at chinet.chi.il.us
Thu Aug 31 23:47:42 AEST 1989
In article <1679 at hydra.gatech.EDU> wj4 at prism.gatech.EDU (JOYE,WILLIAM A) writes:
>Ok, C gurus of the world... is the following code portable and why or why
>not?
>
> void (*f)() = printf;
> f("Hello, world\n"); /* are these two methods equivalent? */
> (*f)("Hello, world again\n" );
They are.
I noticed the same thing on AT&T 3b2/400's and 3b1's. The assembly code
generated for either form is exactly the same. The compiler is not the
latest release. (I'd made a typo once and expected the program to fail.
It didn't.)
In effect, this means that for pointers to functions, the pointer
is not dereferenced, thus in effect f == *f.
K & R are quite definite in stating the correct form is (*f)(), but
apparently even the gods can lie.
If f holds the address of the start of the function, *f really doesn't
have any meaning.
--
---------------------
John Mundt Teachers' Aide, Inc. P.O. Box 1666 Highland Park, IL
john at chinet.chi.il.us
(312) 998-5007 (Day voice) || -432-8860 (Answer Mach) && -432-5386 Modem
More information about the Comp.lang.c
mailing list