View previous topic :: View next topic |
Author |
Message |
dev39 Guest
|
Pointer to function |
Posted: Thu Dec 31, 2009 6:50 am |
|
|
Hi,
I tried to create a pointer to function within a structure but it gives me error. Simple pointer to function (out side structure compiles file). Can someone let me know whats going wrong here? The compiler version I am using is 4.0
Code: |
#include <18F46K20.h>
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
typedef int err_t;
typedef err_t (* _ptr_to_fn_)();
err_t test(){
return 0;
}
struct l2cap_pcb
{
_ptr_to_fn_ fn;
};
void main()
{
struct l2cap_pcb *pcb;
_ptr_to_fn_ tmp_fn;
*tmp_fn=test;
(*tmp_fn)(); //this compiles fine
(*pcb->fn)=test;
(*pcb->fn)();//this gives error
}
|
Thanks |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Thu Dec 31, 2009 7:42 am |
|
|
4.0 is not the correct compiler version.
The version number is in the format of 4.xxx (3 digits after the decimal point). _________________ Google and Forum Search are some of your best tools!!!! |
|
|
dev39 Guest
|
Pointer to function- compiler version is 4.078 |
Posted: Thu Dec 31, 2009 7:53 am |
|
|
The compiler version is 4.081 |
|
|
dev39 Guest
|
Pointer to function- compiler version is 4.081 |
Posted: Thu Dec 31, 2009 7:54 am |
|
|
Sorry for the confusion in last post
The compiler version is 4.081 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 31, 2009 3:49 pm |
|
|
I'm more worried about the indirection levels here.
pcb, is declared as a pointer to a structure containing a pointer to a function, but at no point is this pointer made to point to a physical structure. It could be pointing anywhere.....
Best Wishes |
|
|
dev39 Guest
|
Thanks guys |
Posted: Thu Dec 31, 2009 11:42 pm |
|
|
Thanks guys for useful responses. |
|
|
|