Use of Function Pointer in Embedded Systems

Hi All, I am Ravi Kumar.N, I have an issue regarding function pointer.

1) What is the advantage of using function pointers in embedded systems.

2) What is the difference between an ordinary function call and calling a function through function pointer.

3)Where all, function pointers can be used.

With Regards, Ravi Kumar.N

Reply to
ravikumar.n
Loading thread data ...

Hi All, I am Ravi Kumar.N, I have an issue regarding function pointer.

1) What is the advantage of using function pointers in embedded systems.

2) What is the difference between an ordinary function call and calling a function through function pointer.

3)Where all, function pointers can be used.

With Regards, Ravi Kumar.N

Reply to
ravikumar.n

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)

Reply to
Ignacio G.T.

No particular advantage, embedded systems are nothing special from this point of view.

Click here: , then click the first result.

HTH,

Vadim

Reply to
Vadim Borshchev

There is at least one disadvantage, by making it point to a wrong address either voluntarily or not you can create interesting situations.

you must use them with great care. One safe solution is to initialize them at compile time and not at run time.

You should also avoid explicit casts, and use a typedef.

Reply to
Lanarcam

Sometimes it is just not possible, like ARM ADS compiler generating position-independent code. The only option is run-time initialisation.

And, *anything* should be used with great care :)

Vadim

Reply to
Vadim Borshchev

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.

Paul

Reply to
pbreed

This troll has multi-posted this same query in at least three newsgroups. Ignore it.

--
"If you want to post a followup via groups.google.com, don't use
 the broken "Reply" link at the bottom of the article.  Click on 
 "show options" at the top of the article, then click on the 
 "Reply" at the bottom of the article headers." - Keith Thompson
Reply to
CBFalconer

Homework?

--

Tauno Voipio
tauno voipio (at) iki fi
Reply to
Tauno Voipio

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   |
need a Hand?           London  N1 1LX       | +UK 20 7700 2487
www.shadow.org.uk/products/newhand.shtml
Reply to
Rich Walker

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.