views:

62

answers:

2

What are the differences between normal function and function pointer. One which I know is in case you are using a library in your software stack which gives you only function pointers then you can fill in the pointers for use later.

+1  A: 

A function pointer is just a pointer to a normal function. It can be passed around like any other pointer, and can be invoked somewhere other than where it was created.

Ignacio Vazquez-Abrams
Yup tats right any other differences which u might think?
Sikandar
+2  A: 

Calling a function through a function pointer means the call cannot be inlined; in certain cases, this can result in quite a performance penalty. (For example, C's qsort() going through a function pointer for each compare, vs. C++'s sort() being able to inline the comparison.)

Declaring a function pointer requires a non-trivial syntax that is not as commonly used as other parts of the language, resulting in a "mental speed-bump" for most when reading the source. It is usually typedef'ed for that reason.

DevSolar