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

set_pwm1_duty signature

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



Joined: 28 Jun 2016
Posts: 2

View user's profile Send private message

set_pwm1_duty signature
PostPosted: Tue Jun 28, 2016 9:45 am     Reply with quote

Hello All,
I've encountered a situation which I cant find an answer to, could you please help.

I am trying to create an array of pointers to pwm set functions:
Code:
typedef void (*pfSetPwmDuty)(int16);
fSetPwmDuty setPWM[5];

when i try to assign the set pwm functions the the array the compiler gives me these weird errors:
Code:
setPWM[0] = set_pwm1_duty;

on this line i get
*** Error 48 "testBoxFirmware.c" Line 71(13,26): Expecting a (

I've tried to replace the
Code:
setPWM[0] = set_pwm1_duty;

with my own void foo(int16) and it works perfectly.
For me it seems like the signature of set_pwm1_duty is not a void(int16). Unfortunately I don't have access to this function to check how it was declared.

Anyone has any ideas how to solve this issue?

Thanks a lot
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

Re: set_pwm1_duty signature
PostPosted: Tue Jun 28, 2016 9:55 am     Reply with quote

LeGhimp wrote:

For me it seems like the signature of set_pwm1_duty is not a void(int16). Unfortunately I don't have access to this function to check how it was declared.


For one thing, it isn't declared. Just because it looks like a C function doesn't mean it is a C function. In this case, it's not, its a built-in function, coded as in-line code by the compiler. There is nothing to point to. The second point is that it's effectively overloaded, and its functionality depends on the type of variable it's used with, working differently with an int8 to an int16, so it's signature, if it were a C function, would change.

If you really want to do this sort of thing, and for the most part function pointers have very limited usefulness in PIC code, hence wanting to use them is a red flag, then you'll have to wrap such built-in functions with functions of your own
LeGhimp



Joined: 28 Jun 2016
Posts: 2

View user's profile Send private message

Re: set_pwm1_duty signature
PostPosted: Tue Jun 28, 2016 10:01 am     Reply with quote

RF_Developer wrote:
LeGhimp wrote:

For me it seems like the signature of set_pwm1_duty is not a void(int16). Unfortunately I don't have access to this function to check how it was declared.


For one thing, it isn't declared. Just because it looks like a C function doesn't mean it is a C function. In this case, it's not, its a built-in function, coded as in-line code by the compiler. There is nothing to point to. The second point is that it's effectively overloaded, and its functionality depends on the type of variable it's used with, working differently with an int8 to an int16, so it's signature, if it were a C function, would change.

If you really want to do this sort of thing, and for the most part function pointers have very limited usefulness in PIC code, hence wanting to use them is a red flag, then you'll have to wrap such built-in functions with functions of your own


Thank you. I got the point. But I find it quite confusing because it seems like a function both from the way it looks and the example shown in the manual. It would be nice to mention it in the manual.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jun 28, 2016 10:52 am     Reply with quote

The safe assumption i have always made is that if the
"function" is classic 'C then treat it a such--
but --
if it is PIC SPECIFIC, like the PWM control suite
it is much more likely to be coded inline
just as RF_devel has stated.

Your best friend is the CCS manual
where the set_pwmx() documents plainly
call for a VALUE to be passed.
at compile time - the compiler adjusts to
whether a constant- or an 8 or 16 bit value
is being passed by VALUE - not reference.
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