I use function pointers when changing states in state machine code.
I might use  a Switch-Case function if there are only a few states,
but after that, a function pointer system is more efficient.

boB



--- In [email protected], John Gaughan <[EMAIL PROTECTED]> wrote:
>
> Arindam Biswas wrote:
> > Function pointer has some overhead associated with it. Still WHY
SHOULD we use function pointer instead of calling directly that function.
> >   
> 
> Paul provided an answer but I would like to expand on this slightly: 
> "Because it allows you to change the function being called at runtime."
> 
> The key here is that once you reduce a function to a pointer, you can 
> pass it around like any other variable. You can pass the function 
> address into another function, which can then call it. You can call the 
> function multiple times with different function pointers and have the 
> same code run different functions each time. You can typecast it to an 
> (int *) and assign an integer to it, then enjoy the chaos that ensues.
> 
> -- 
> John Gaughan
>


Reply via email to