bw*****@yahoo.com wrote:
What is the ansi correct way to pass a function when the argument is a
function pointer?
void foo(void (*)());
foo(read);
or
foo(&read);
Please ignore the fact that I am not passing the arguments of read in
the above example. Also, both of the above will compile without
warning.
Functions can be implicitly converted to function pointers, but there's
nothing wrong with making this explicit. If your coding guidelines say
so, you may prefer one or the other, but both are valid C, as long as
read() is declared as something compatible with void().
(The c.l.c FAQ suggests the first form, if this matters to you:
<http://c-faq.com/decl/ptrfuncinit.html>)