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 CCS Technical Support

Are pointers to functions still not supported in CCS PIC C?

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



Joined: 06 Dec 2010
Posts: 25

View user's profile Send private message

Are pointers to functions still not supported in CCS PIC C?
PostPosted: Sun Jul 03, 2016 1:22 pm     Reply with quote

I have written some code that uses a function pointer, it is assigned a value in a C language switch block and the function pointed to is called after the switch block.

The code does not compile. After thinking about it for some time I have a feeling that pointers to functions are not supported by the PIC C Compiler. Is this correct? I am using a PIC 18F device.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 03, 2016 1:35 pm     Reply with quote

Yes, they normally work. Post your small but complete test program
and your compiler version.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: Are pointers to functions still not supported in CCS PIC
PostPosted: Mon Jul 04, 2016 1:54 am     Reply with quote

matrixofdynamism wrote:
The code does not compile.


What error messages do you get?

Quote:
After thinking about it for some time I have a feeling that pointers to functions are not supported by the PIC C Compiler. Is this correct?


No, it is not correct, function pointers are supported, but there restrictions. Basically, the compiler has to be able to resolve the pointer. Assignment at runtime, i.e. in your switch block, is fine provided that compiler can work out where the function is. As we saw recently in another thread, built-in functions, i.e. those implemented by the compiler, are often not functions in the C sense and cannot be pointed to.

Generally speaking, its often better to avoid function pointers in CCS C. Its certainly easier. and more maintainable (e.g. is more likely to work in future complier versions). This is due to the implications of the Harvard architecuture of most PICS. In your case, do you really need to assign a pointer in a switch and then call it afterwards? It might require reorganisation, but can you not simply call the relevant routine directly in the switch block?
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