IMO, the same as using them in non-embedded systems.
One level more of indirection.
I use explicit function pointers only in function tables --to implement state-mechines (sometimes) or call-backs (some-times)--, and in some special situations I cannot remember now (Friday afternoon, one beer more than needed)
I use function pointer a lot when writing library code where some action or event might be of interest to the end programmer.
I'll give you one use of a function pointer. Our system (Netburner) has a facility for updating the code over the network.
Before the code is updated one might want to shut down critical processes. The update code is part our our library, the shut down code is most likely our customers own code. So we provide a shutdown function pointer. It gets initialized to NULL, if the customer wants to have his code do something for shutdown, he points the global function pointer at the his shutdown code.
Our library checks to see if the pointer is null, if not it calls the function at the aproprriate place.
It is possible to hide the called function from the calling function. This means that third-party software on the embedded system does not know where it is being called from, and so cannot present an inappropriate user interface for the country the system is deployed in.
Also, it increases the metric "information hiding" in the programmer analysis package, thus resulting in increased payments for higher quality code to the programmer.
As far as we have been able to tell in this newsgroup, calling a function through a function pointer will call a library subroutine on the commercial compilers. On sdcc, it will generate inline code - this is much less efficient for many calls, but if you were worrying about efficiency you wouldn't be using function pointers.
In England, we prefer not to use them in a room where mixed-gender groups are gathered. Mostly, this is because in these situations we have more direct access to the member parts of friend functions, and so can call them directly. However, in other countries, excess drapery is required in mixed-gender groups - in these areas, the passing around of function pointers is the only way to excite these member functions.
cheers, Rich.
[following the comp.arch tradition in these things]
--
rich walker | Shadow Robot Company | rw@shadow.org.uk
technical director 251 Liverpool Road |
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.