??? 11/09/07 17:37 Read: times |
#146819 - I use function pointers all the time Responding to: ???'s previous message |
It's a great technique for implementing UI code (E.g. LCD + Keypad) without a massive switch statement or state machine or similar.
Here is my declaration: void (*pUIFocus)(); // Holds the addr of the current menu func. Here is setting the UI to the main menu: pUIFocus = UIMain; // Set the UI context. Here is my UI code being executed in the main program loop: // Execute the current UI context. (*pUIFocus)(); Then each UI menu is in it's own C file (if there are a lot of them). Each UI has an initialzation routine which sets up any variables or hardware and then sets the context. This is pretty common stuff. I can't recall using pointers to pointers on a '51 but I may have. I definitely don't do anything that uses a heap. And for those that complain that this might be slow (it isn't), you might want to stay away from things like printf(). |
Topic | Author | Date |
C : pointers of function und pointers of pointers | 01/01/70 00:00 | |
Function pointers and stuff | 01/01/70 00:00 | |
Parameter passing in C | 01/01/70 00:00 | |
C FAQ | 01/01/70 00:00 | |
Function pointer demo | 01/01/70 00:00 | |
Heads up | 01/01/70 00:00 | |
True | 01/01/70 00:00 | |
I use function pointers all the time | 01/01/70 00:00 | |
void-void function pointers need not be slow | 01/01/70 00:00 | |
correct, with a caveat | 01/01/70 00:00 | |
thank you all. | 01/01/70 00:00 |