|
|
View previous topic :: View next topic |
Author |
Message |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
Expecting LVALUE such as variable name or expresion |
Posted: Tue Apr 30, 2019 7:40 am |
|
|
CCS 5.078
MPLAB X IDEv 5.15
PIC24FJ1024GB610
I'm getting this error
Expecting LVALUE such as variable name or * expression
Code: | DummyCheck=swap(0x0F & BinNumberFromCharI(GPS_RxBufferGSA[++ParserOffset])); |
And I don't understand why because I'm using the same code on a PIC18F67J50
Now I just read the help and says that the swap() function doesn't return a value, so, Why is working on the PIC18F? _________________ Electric Blue |
|
|
dluu13
Joined: 28 Sep 2018 Posts: 395 Location: Toronto, ON
|
|
Posted: Tue Apr 30, 2019 7:49 am |
|
|
that's weird because in my manual, it says that only PCD has a return value. |
|
|
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Tue Apr 30, 2019 8:01 am |
|
|
I have a mix info, I have a PDF and on the syntax says
swap(lvalue)
result=swap(lvalue)
On the CCS help(F11 in MPLAB IDE) there is a warning
Returns:
undefined - WARNING: this function does not return the result
Now I just splitted in two steps and it works, or at least I get no error about.
Code: |
DummyCheck=0x0F & BinNumberFromCharI(GPS_RxBufferGSA[++ParserOffset]);
swap(DummyCheck);
|
_________________ Electric Blue |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Tue Apr 30, 2019 8:49 am |
|
|
There are two separate probably 'nasties' here:
First thing, the 'swap' function on PCB/M/H, should not have a return
value. It directly calls the processor's 'swap' instruction, which toggles
the nibbles in a 8bit byte.
However compiling it shows, that what happens if you use:
rval=swap(val);
if that the byte in 'val', is swapped (as expected), and then this byte
is passed 'back' to 'rval', so you actually have two copies of the 'swapped'
result.....
Now PCD is fractionally different, since it does not have a direct 'in
RAM' swap instruction. It instead has to copy the byte from the RAM
into one of the W SFR's, swap it here, and then move the byte back
to the RAM.
Compiling on PCD, shows it does do this, and also copies the result
into rval, just as in PCH.
However this is with a _byte_ passed to it.
So the first is actually with types. Remember the default 'type'
on PCD, is a signed int16. If a function is declared to return 'int', this
is what it will return. Now, swap on PCD, swaps the nibbles if called
with a byte, but swaps the bytes if called with an int16. Now swapping
the bytes on a signed type, will lose the sign of the value, and should
not really be allowed.
So question becomes what is BinNumberFromChar declared to return?.
If it is an 'int' then this will not be doing what is expected, and would
cause issues. If DummyCheck, is declared as an int8, it'll corrrectly force
the swap 'back' to the PCH behaviour of swapping nibbles.
The second issue though is with temporary variables. In PCM/H, there is
no data stack, so a function that returns a value, always returns it as
a RAM value in the compiler's 'scratch' storage, which can then be
'swapped'. In PCD though a value will be returned in the stack. There
is no compiler 'swap' function for data in the stack. Hence the error.
So to use 'swap' on PCD the return value has to be copied back to local
RAM. |
|
|
|
|
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
|