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

CCS Compiler Error declaring a function

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



Joined: 10 Dec 2018
Posts: 10

View user's profile Send private message

CCS Compiler Error declaring a function
PostPosted: Mon Mar 11, 2019 7:11 am     Reply with quote

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!
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 11, 2019 7:20 am     Reply with quote

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?
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 11, 2019 7:23 am     Reply with quote

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...
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Mar 11, 2019 7:26 am     Reply with quote

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.
InterruptHandler



Joined: 10 Dec 2018
Posts: 10

View user's profile Send private message

PostPosted: Mon Mar 11, 2019 7:33 am     Reply with quote

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.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Mar 11, 2019 7:39 am     Reply with quote

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.
InterruptHandler



Joined: 10 Dec 2018
Posts: 10

View user's profile Send private message

PostPosted: Tue Mar 12, 2019 2:35 am     Reply with quote

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!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Mar 12, 2019 6:02 am     Reply with quote

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... Smile

Jay
InterruptHandler



Joined: 10 Dec 2018
Posts: 10

View user's profile Send private message

PostPosted: Tue Mar 12, 2019 6:03 am     Reply with quote

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... Smile

Jay

Laughing Laughing Laughing thanks for hint!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Mar 12, 2019 8:53 am     Reply with quote

'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....
jeremiah



Joined: 20 Jul 2010
Posts: 1358

View user's profile Send private message

PostPosted: Wed Mar 13, 2019 6:43 pm     Reply with quote

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.
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