CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pointer to function

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
dev39
Guest







Pointer to function
PostPosted: Thu Dec 31, 2009 6:50 am     Reply with quote

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: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Dec 31, 2009 7:42 am     Reply with quote

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
PostPosted: Thu Dec 31, 2009 7:53 am     Reply with quote

The compiler version is 4.081
dev39
Guest







Pointer to function- compiler version is 4.081
PostPosted: Thu Dec 31, 2009 7:54 am     Reply with quote

Sorry for the confusion in last post

The compiler version is 4.081
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 31, 2009 12:28 pm     Reply with quote

Here are some threads that explain how to use function pointers in
a structure with CCS:
http://www.ccsinfo.com/forum/viewtopic.php?t=35500
http://www.ccsinfo.com/forum/viewtopic.php?t=33458
http://www.ccsinfo.com/forum/viewtopic.php?t=31637
Ttelmah
Guest







PostPosted: Thu Dec 31, 2009 3:49 pm     Reply with quote

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
PostPosted: Thu Dec 31, 2009 11:42 pm     Reply with quote

Thanks guys for useful responses.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group