View previous topic :: View next topic |
Author |
Message |
meebee Guest
|
Function pointers |
Posted: Thu May 20, 2004 7:53 pm |
|
|
PCH version 3.158
I wanted to write a dispatcher function, with an array storing pointes to callback functions. Given a certain event I wanted to call the appropriate callback function.
Unfortunately it seems that the pic c compiler doesnt support function pointers. E.g:
void do_nothing() {}
void main() {
void (*p)();
p = do_nothing;
p();
}
Gives me this error message:
Error 117: Improper use of a function identifier.
Did I miss something or is the compiler not capable with dealing of function pointers? Is there any workaround for this?
Any help appreciated,
Michael |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
Function Pointers |
Posted: Fri May 21, 2004 9:27 am |
|
|
There have a LOT of discussions about pointers on the board! Search this board for function pointers and you will get a lot of info and some sample code! |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
Re: Function pointers |
Posted: Fri May 21, 2004 9:59 am |
|
|
meebee wrote: | PCH version 3.158
I wanted to write a dispatcher function, with an array storing pointes to callback functions. Given a certain event I wanted to call the appropriate callback function.
Unfortunately it seems that the pic c compiler doesnt support function pointers. E.g:
void do_nothing() {}
void main() {
void (*p)();
p = do_nothing;
p();
}
Gives me this error message:
Error 117: Improper use of a function identifier.
Did I miss something or is the compiler not capable with dealing of function pointers? Is there any workaround for this?
Any help appreciated,
Michael |
What is the application? Maybe there is a better solution that does not involve function pointers. The only place I can think of where function pointers would be the best solution would be in the creation of a multi tasking system for a complex system. Thats not the sort of thing you do with a PIC. I really am curious why you want to use function pointers. |
|
|
meebee
Joined: 21 May 2004 Posts: 2
|
|
Posted: Fri May 21, 2004 4:14 pm |
|
|
This is the hardware platform I use:
http://particle.teco.edu/artefacts.html
The data that is transmitted over RF always has a certain type.
There are e.g. different control types/messages and depending on the application you have to respond differently.
So what I want to to is to use a dispatcher and a register_callback function. Then you can write your custom handler function, register it and it is invoked appropriately by the dispatcher.
My main goal is provide a development platform where other developers can write applications upon. With the aforementioned mechanism I can cleanly separate the underlying framework from the application that is written with it. |
|
|
|