Function Pointers as Arguments (ansi question)

B

bwaichu

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.

Thanks,

Brian
 
G

Guest

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>)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top