Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!att!chinet!john From: john@chinet.chi.il.us (John Mundt) Newsgroups: comp.lang.c Subject: Re: pointers to functions Message-ID: <9429@chinet.chi.il.us> Date: 31 Aug 89 13:47:42 GMT References: <1679@hydra.gatech.EDU> Reply-To: john@chinet.chi.il.us (John Mundt) Organization: Chinet - Public Access Unix Lines: 28 In article <1679@hydra.gatech.EDU> wj4@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@chinet.chi.il.us (312) 998-5007 (Day voice) || -432-8860 (Answer Mach) && -432-5386 Modem