pointers to functions

Norman Diamond diamond at csl.sony.co.jp
Fri Sep 1 12:32:10 AEST 1989


In article <1679 at hydra.gatech.EDU> wj4 at 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 at 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.



More information about the Comp.lang.c mailing list