prev up next   top/contents search

comp.lang.c FAQ list · Question 1.34

Q: I finally figured out the syntax for declaring pointers to functions, but now how do I initialize one?


A: Use something like

extern int func();
int (*fp)() = func;

When the name of a function appears in an expression, it ``decays'' into a pointer (that is, it has its address implicitly taken), much as an array name does.

A prior, explicit declaration for the function (perhaps in a header file) is normally needed, as shown. The implicit external function declaration that can occur when a function is called does not help when a function name's only use is for its value.

See also questions 1.25 and 4.12.


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North