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

Expecting LVALUE such as variable name or expresion

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



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

Expecting LVALUE such as variable name or expresion
PostPosted: Tue Apr 30, 2019 7:40 am     Reply with quote

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? Question
_________________
Electric Blue
dluu13



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

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

PostPosted: Tue Apr 30, 2019 7:49 am     Reply with quote

that's weird because in my manual, it says that only PCD has a return value.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Tue Apr 30, 2019 8:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Apr 30, 2019 8:49 am     Reply with quote

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