View previous topic :: View next topic |
Author |
Message |
enovak
Joined: 24 Nov 2021 Posts: 5
|
Expecting ; (but it shouldn't be) |
Posted: Thu Dec 16, 2021 1:53 pm |
|
|
I'm using version 5.075 of the PCH compiler and compiling a piece of 3rd party code. I am getting the following error with the code below (I expanded out the macros to show exactly what the code is). The same macros are used elsewhere in the code with no problem. Does anyone have any ideas what might be causing this error? Thank you.
*** Error 76 "..\..\..\CMock\src\cmock.c" Line 111(81,82): Expect ;
Code: | *(uint16*)((uint16)next - (uint16)(uint16)((sizeof(uint16) > (uint16)(1u << 1)) ? sizeof(uint16) : (uint16)(1u << 1))) = (uint16)((uint16)obj - (uint16)CMock_Guts_Buffer); |
|
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1328
|
|
Posted: Thu Dec 16, 2021 5:43 pm |
|
|
It appears to be invalid C code. You have:
expr ? expr : expr = expr;
Which isn't valid C as you can't have
expr = expr;
It has to be
var = expr;
The error is telling you that it didn't expect the "= expr" at the end, it expected a semicolon (since you used the ternary operator for the IF).
Specifically with the code you supplied, it [correctly] expects:
expr ? expr : expr ; // <== semicolon here |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Fri Dec 17, 2021 6:46 am |
|
|
My head and eyes hurt from trying to understand what that line of code really does.....
though I was thinking there might be a 'typo' as he said it worked(compiled ?) at other locations within the program. |
|
![](templates/subSilver/images/spacer.gif) |
enovak
Joined: 24 Nov 2021 Posts: 5
|
|
Posted: Fri Dec 17, 2021 7:03 am |
|
|
I agree that this has made my head hurt as well. I had to expand out the macros just to get an idea of what is going on. What's interesting is that I'm able to get this to compile if instead of evaluating a condition in the first part of the conditional statement I instead just make this 1. That pushed me to believe there was something with that part of the conditional, but as I stated earlier this same code compiles correctly in other locations of the code. |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1328
|
|
Posted: Fri Dec 17, 2021 12:58 pm |
|
|
It shouldn't compile anywhere as you cannot have expr = expr in C. It could be that we are missing context of the rest of your code, but the blurb as posted shouldn't compile. Normally we ask for a "minimally compilable example", which should be easy to generate for this line of code.
It could also be that when you call this macro elsewhere that it replaces some of the code above with code that correctly compiles. Can't really tell without a working example though. |
|
![](templates/subSilver/images/spacer.gif) |
enovak
Joined: 24 Nov 2021 Posts: 5
|
|
Posted: Fri Dec 17, 2021 2:38 pm |
|
|
In my testing of this I was able to get the following to compile.
Code: | *(uint16*)((uint16)next - (uint16)(uint16)((1) ? sizeof(uint16) : (uint16)(1u << 1))) = (uint16)((uint16)obj - (uint16)CMock_Guts_Buffer); |
I replaced the Code: | sizeof(uint16) > (uint16)(1u << 1) | with 1 so that the conditional check was always TRUE and this worked. |
|
![](templates/subSilver/images/spacer.gif) |
jeremiah
Joined: 20 Jul 2010 Posts: 1328
|
|
Posted: Fri Dec 17, 2021 4:31 pm |
|
|
Ok, I see what you are doing. Converting raw numbers to pointers and de-referencing it, which makes it viable C, since that makes the expr into a temporary var. Sorry about that. The code is incredibly hard to read.
Best you can probably do is send an email to CCS support (or call them if you don't like email) if you think you have found a bug.
There's parsing bugs in v5.105 (I've confirmed 2 with CCS support), but I don't know about 5.075 |
|
![](templates/subSilver/images/spacer.gif) |
|