On Thu, Jul 3, 2008 at 11:16 AM, Arindam Biswas <[EMAIL PROTECTED]> wrote:
> Hi Friends,
> I need to understand a very simple doubt:
> Function pointer has some overhead associated with it. Still WHY SHOULD we use
> function pointer instead of calling directly that function.

There is no difference between a 'function' and a 'function pointer'
except the syntax. The function has parentheses after it:

int foo(void){
   return 1;
}

int (bar*)(void) = foo;

foo(); // calls foo
bar(); // calls foo - no additional overhead from the line above.

> I understand the use e..g: for callback impplementation etc etc. But I need to
> understand the unlerlying logic behind using of function pointer.

Because it allows you to change the function being called at runtime.
The mechanism (internally - not that you should be worrying about it)
is generally the same regardless of whether you're using the 'function
name' as it were (foo in my example above) or a 'function pointer'
pointing to the function (bar in my example.)

-- 
PJH

'Two Dead in Baghdad' not  'product-friendly'  - Kent Ertugrul, chief
executive of Phorm.

http://shabbleland.myminicity.com/env

Reply via email to