??? 06/27/05 22:36 Modified: 06/27/05 22:39 Read: times |
#96059 - There can be a gain. Responding to: ???'s previous message |
Function pointers in C51 can be used if care is taken. There are some applications wherein their use can and will save tons and tons of code over other approaches that could be used. The function pointers can also offer considerable performance improvement over long strings of IF/ELSES or SWITCH statements. Here are my recommendations to a good starting point if you consider a need to use function pointers:
1) Try to use void func(void) types of functions if at all possible. 2) Try to avoid the declaration of local variables in the target routines. If you must have them then make sure that the Keil Linker overlay table is properly configured. This takes a huge amount of extra manual work. It is better to manually manage any variables needed in the target functions as global variables. 3) Make sure that all the target routines are setup to use the same register banking. I recommend keeping them all using the default bank zero same as the mainline code. 4) Stay away from trying to use code bank switching if you use function pointer calls. It will usually break when trying to make calls across bank boundaries where an implicit bank switch is implied in the call. 5) I would also recommend not trying to use function pointers inside interrupt service routines. Now while there is no technical reason to oppose this usage I recommend it becasue of the complications that arise out of the common usage of alternate register banks in the interrupt service routines. 6) Study the compiler generated machine language for all your function pointer usages and be COMPLETELY aware of how this stuff is working underneith the bonnet of your C code. This of course will require a seasoned experience with the 8051 assembly language and if you came to C51 as a "C only" programmer then forget about function pointers all together. Final Comment: If you use function pointers be prepared to have to spend some time dealing with issues. Each time I got into function pointers on a new '51 project one or more days were required to iron out "issues". Good Luck Michael Karas |
Topic | Author | Date |
Coding a Jmp table in C | 01/01/70 00:00 | |
Jmp Tables in C | 01/01/70 00:00 | |
you do not | 01/01/70 00:00 | |
Call table? | 01/01/70 00:00 | |
Of course not! | 01/01/70 00:00 | |
use jmp@a+dptr | 01/01/70 00:00 | |
jmp table not in C | 01/01/70 00:00 | |
Wrong ends of sticks? | 01/01/70 00:00 | |
You do not control the Compiler Output | 01/01/70 00:00 | |
You can not have your cake and eat it to | 01/01/70 00:00 | |
Jump Table in C | 01/01/70 00:00 | |
Call Table? (again) | 01/01/70 00:00 | |
Call Table? (again) | 01/01/70 00:00 | |
I never did use function pointers | 01/01/70 00:00 | |
No pain, no gain. | 01/01/70 00:00 | |
the overlaying | 01/01/70 00:00 | |
There can be a gain. | 01/01/70 00:00 | |
My 2 cents worth | 01/01/70 00:00 | |
Incorrect | 01/01/70 00:00 | |
As Matter of Fact....![]() | 01/01/70 00:00 |