View previous topic :: View next topic |
Author |
Message |
InterruptHandler
Joined: 10 Dec 2018 Posts: 10
|
CCS Compiler Error declaring a function |
Posted: Mon Mar 11, 2019 7:11 am |
|
|
Dear Sirs and Madams!
In my project, inside header (.h) file I declare following function:
Code: |
void Write_3D_Timing_Offsets(const uint8_t& xvQuadurpleView);
|
In my implementation (.c) file I implemented upper method:
Code: |
void Write_3D_Timing_Offsets(const uint8_t& xvQuadurpleView) //"01 D6 FC 0A FF FF 16 27 17 27 2D 4E 00 00"
{
UART_Send_Byte(0x01);
UART_Send_Byte(0x0B);
UART_Send_Byte(0xFD);
UART_Send_Byte(0x08);
// we will use MSB of LO_offset for quadruple view status flag
if(xvQuadurpleView==1)
{
LO_offset|=0x8000; // set the MSB of LC_offset
} // if
UART_Send_Byte(LO_offset);
UART_Send_Byte(LO_offset >> 8);
UART_Send_Byte(LC_offset);
UART_Send_Byte(LC_offset >> 8);
UART_Send_Byte(RO_offset);
UART_Send_Byte(RO_offset >> 8);
UART_Send_Byte(RC_offset);
UART_Send_Byte(RC_offset >> 8);
} // Write_3D_Timing_Offsets
|
I tried to compile this project, however, I get weird syntax error(s) regarding ")" missing:
Quote: |
E:\Projects\RFECB_XPAND_VDC_v102\RFECB_XPAND_VDC_v102.h:88:36: Error#32 Expecting a , or )
|
I am aware this is some dumb mistake, however, what is wrong, I cannot see it! |
|
![](templates/subSilver/images/spacer.gif) |
dluu13
Joined: 28 Sep 2018 Posts: 395 Location: Toronto, ON
|
|
Posted: Mon Mar 11, 2019 7:20 am |
|
|
The only thing I can think of is some problem with includes at the top of your files... What happens when you get rid of either the definition or declaration? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Mon Mar 11, 2019 7:23 am |
|
|
Ok, I can't see it either but...
If the program compiles without that function...
simply comment out each line, one by one ( put '// ' in front....)
eventually it should compile. The LAST line you commented should be the problem..
However...
the error message may refer to some code several line above... |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Mon Mar 11, 2019 7:26 am |
|
|
The '&' syntax, is 'pass by reference'. It allows a function to access a
variable declared in the calling function 'by reference'. Talking to it in
the function as if it was declared in here.
You can't pass a 'constant' (which is not really a 'variable' in this case),
'by reference'.
Since the compiler can't work out how to access the variable here, it is
getting totally confused....
Using the syntax:
void Write_3D_Timing_Offsets(uint8_t &xvQuadurpleView)
and calling it with a variable, it merrily compiles. |
|
![](templates/subSilver/images/spacer.gif) |
InterruptHandler
Joined: 10 Dec 2018 Posts: 10
|
|
Posted: Mon Mar 11, 2019 7:33 am |
|
|
Ttelmah wrote: | The '&' syntax, is 'pass by reference'. It allows a function to access a
variable declared in the calling function 'by reference'. Talking to it in
the function as if it was declared in here.
You can't pass a 'constant' (which is not really a 'variable' in this case),
'by reference'.
Since the compiler can't work out how to access the variable here, it is
getting totally confused....
Using the syntax:
void Write_3D_Timing_Offsets(uint8_t &xvQuadurpleView)
and calling it with a variable, it merrily compiles. |
Thanks, man, solved, however, gcc allows such function parameter declaration. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Mon Mar 11, 2019 7:39 am |
|
|
Remember 'by default', CCS treats a const as a _ROM_ value.
Switch it to ANSI mode, and it'll accept a const by reference value, but you'll
have to put the 'const' after the type declaration not before:
void Write_3D_Timing_Offsets(uint8_t const &xvQuadurpleView)
In gcc, a 'const' implies a _variable_ that cannot be changed. Different
from the CCS 'rom' assumption. |
|
![](templates/subSilver/images/spacer.gif) |
InterruptHandler
Joined: 10 Dec 2018 Posts: 10
|
|
Posted: Tue Mar 12, 2019 2:35 am |
|
|
Ttelmah wrote: | Remember 'by default', CCS treats a const as a _ROM_ value.
Switch it to ANSI mode, and it'll accept a const by reference value, but you'll
have to put the 'const' after the type declaration not before:
void Write_3D_Timing_Offsets(uint8_t const &xvQuadurpleView)
In gcc, a 'const' implies a _variable_ that cannot be changed. Different
from the CCS 'rom' assumption. |
Ahaa, this is the difference, thank you very much for clarification! |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9174 Location: Greensville,Ontario
|
|
Posted: Tue Mar 12, 2019 6:02 am |
|
|
You need to understand that CCS C is close to K&R C and not gcc. While they are both 'C' they are not identical.
I'm lucky as the only C I've ever used is CCS C...
Jay |
|
![](templates/subSilver/images/spacer.gif) |
InterruptHandler
Joined: 10 Dec 2018 Posts: 10
|
|
Posted: Tue Mar 12, 2019 6:03 am |
|
|
temtronic wrote: | You need to understand that CCS C is close to K&R C and not gcc. While they are both 'C' they are not identical.
I'm lucky as the only C I've ever used is CCS C...
Jay |
thanks for hint!!! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19368
|
|
Posted: Tue Mar 12, 2019 8:53 am |
|
|
'const' didn't actually exist originally in K&R...
It was introduced by CCS, as a way of dealing with the PIC, for
handling 'virtual' elements stored in ROM.
Then a couple of years later it appeared in ANSI C, with their approach
having instead a variable that could not be changed by the code.
This particularly suited more complex chips where memory areas
could be hardware protected.
It then appeared in the second edition of K&R (the ANSI edition).
CCS retained their approach for standard operation, but offered over
the years the option to instead behave much closer to the ANSI version.
Actually using const for an element accessed 'by reference', strikes as
a ludicrously complex way of doing things. At the end of the day, if a
value cannot be changed by the subroutine, then pass the element by
value. The whole 'point' of 'by reference', is to allow the subroutine
to modify values from the calling routine, without having to get involved
in pointers. So the approach strikes as a too complex solution.... |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1328
|
|
Posted: Wed Mar 13, 2019 6:43 pm |
|
|
The main reason to pass by reference to const (at least in c++) is to get read access to very large data structures (or even classes). Passing those by value is fairly costly.
I haven't checked recently, but CCS used to auto inline any function that used "by reference" parameters (at least on pic24's). Is that no longer the case? In some of my code bases (back around the 5.025 days) it made my code size explode. I'm hoping they worked around that by now, but haven't tested. |
|
![](templates/subSilver/images/spacer.gif) |
|