+ 1
What is the use of function pointers?
When to use function pointers
7 Answers
+ 6
Another use for function pointers is setting up "listener" or "callback" functions that are invoked when a particular event happens. The function is called, and this notifies your code that something of interest has taken place.Â
+ 4
The most common use is to pass a function pointer to another function as a callback function.
+ 2
Another use is that it can save time. If you use a function attached to an object or a module frequently, you can store it's reference in a variable for reuse.
Import somemodule
Name = somemodule.alligator.blender.trex.bee.themeaningoflife.generate.name()
Print(Name())
+ 1
Another use of function pointer is implementing something like class in C code.
you can declare a struct inside it use malloc to implent properties and use function pointer to implent methods
+ 1
Function pointers can be useful when you want to create callback mechanism, and need to pass address of a function to another function. They can also be useful when you want to store an array of functions, to call dynamically for example. Callback routines appear to be the most common scenario put forth thus far.
0
Pointers to functions, or function pointers, point to executable code for a function in memory.