[I've combined and restored some context from multiple posts.]
Paul Herring <pauljherr...@...> wrote:
> Bill Cunningham wrote:
> > I would like to start writing code and calling functions
> > in C code with a pointer to a function.
In C, it's impossible to call a function without using a pointer!
Function identifiers will generally decay to function pointers.
[Exceptions being sizeof (which is a constraint violation), and
the address operator.]
#include <stdio.h>
int main(void)
{
(*******printf)("42\n");
return 0;
}
> > int func(int num);
> > void (*pf)(int num); /* Is a parameter required? */
>
> 'int' is required, 'num' isn't.
int isn't strictly required either.
In C, you can assign a non-variadic function pointer to a pointer
to a function of unspecified parameters, without a cast, so long
as the return types are compatible.
> > pf=func; /*here's where I know the name of the function */
Since the return types aren't compatible here, this is a
constraint violation, with or without the int parameter.
<snip>
--
Peter