|
|
View previous topic :: View next topic |
Author |
Message |
LeGhimp
Joined: 28 Jun 2016 Posts: 2
|
set_pwm1_duty signature |
Posted: Tue Jun 28, 2016 9:45 am |
|
|
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
|
Re: set_pwm1_duty signature |
Posted: Tue Jun 28, 2016 9:55 am |
|
|
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
|
Re: set_pwm1_duty signature |
Posted: Tue Jun 28, 2016 10:01 am |
|
|
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
|
|
Posted: Tue Jun 28, 2016 10:52 am |
|
|
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. |
|
|
|
|
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
|