Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!wugate!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond From: diamond@csl.sony.co.jp (Norman Diamond) Newsgroups: comp.lang.c Subject: Re: pointers to functions Keywords: pointers, functions, portable Message-ID: <10779@riks.csl.sony.co.jp> Date: 1 Sep 89 02:32:10 GMT References: <1679@hydra.gatech.EDU> Reply-To: diamond@riks. (Norman Diamond) Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan Lines: 27 In article <1679@hydra.gatech.EDU> wj4@prism.gatech.EDU (JOYE,WILLIAM A) writes: >extern void printf; >main() >{ > void (*f)() = printf; > f("Hello, world\n"); /* are these two methods equivalent? */ > (*f)("Hello, world again\n" ); >} The two methods are equivalent. But I have a question: why does it work under gcc? I understand that gcc uses different calling conventions for ordinary functions and stdargs (varargs) functions. That is why you cannot declare a prototype as just "()" without "..." and then define it with "...". The definition of f makes (*f) non-stdargs. But the actual printf expects stdargs. So why does it work?! -- Norman Diamond, Sony Corporation (diamond@ws.sony.junet) The above opinions are inherited by your machine's init process (pid 1), after being disowned and orphaned. However, if you see this at Waterloo or Anterior, then their administrators must have approved of these opinions.