Error: invalid lvalue in assignment

New to XMOS and XCore? Get started here.
Post Reply
JohnRobert
Active Member
Posts: 34
Joined: Fri Nov 02, 2012 8:10 am

Error: invalid lvalue in assignment

Post by JohnRobert »

Title says it all! I've been getting this error (invalid lvalue in assignment) on the line "n = toStrnig(contrast);", of the following code:

Code: Select all

void cmucamCameraContrast(out port TXD, in port RXD, char buffer[], int contrast){
	char n[3];
	char r[10];
	n = toString(contrast);
	appendString("CC ", n, r);
	sendCommand(TXD, r);
	getResult(RXD, buffer);
}
Can't figure out for the life of me what it is - what is this?

-John


richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

JohnRobert wrote:Title says it all! I've been getting this error (invalid lvalue in assignment)
As with C, you can't assign one array to another using '=' and you can't return arrays from functions.

You will need to change your toString() function to take the array to write the string to as a parameter.

Code: Select all

void cmucamCameraContrast(out port TXD, in port RXD, char buffer[], int contrast){
   char n[3];
   char r[10];
   toString(contrast, n);
   appendString("CC ", n, r);
   sendCommand(TXD, r);
   getResult(RXD, buffer);
}
Alternatively if array always consists of 3 elements you could wrap it in a structure - then you can treat it as a value that can be assigned / returned as normal.
JohnRobert
Active Member
Posts: 34
Joined: Fri Nov 02, 2012 8:10 am

Post by JohnRobert »

Ahh, yes, I had forgotten about that, thanks! It doesn't have any issues now! My code is now:

Code: Select all

void cmucamCameraContrast(out port TXD, in port RXD, char buffer[], int contrast){
	char n[5];
	char r[10];
	toString(n, contrast);
	appendString("CC ", n, r);
	sendCommand(TXD, r);
	getResult(RXD, buffer);
}
Just out of curiosity, I tried doing:

Code: Select all

void cmucamCameraContrast(out port TXD, in port RXD, char buffer[], int contrast){
	char n[5];
	char r[10];
	n = "1234";
	appendString("CC ", n, r);
	sendCommand(TXD, r);
	getResult(RXD, buffer);
}
But I get the same lvalue error on the line "n='1234';", why is this so?

Thanks for your help!

-John
richard
Respected Member
Posts: 318
Joined: Tue Dec 15, 2009 12:46 am

Post by richard »

JohnRobert wrote:But I get the same lvalue error on the line "n='1234';", why is this so?
This is rejected for the same reason your original program is rejected - it is an assignment where the left hand side is an array. Note you can use '=' to initialize a declaration, i.e.

Code: Select all

int n[5] = "1234";
is allowed but:

Code: Select all

int n[5];
n = "1234";
is not
JohnRobert
Active Member
Posts: 34
Joined: Fri Nov 02, 2012 8:10 am

Post by JohnRobert »

Cheers! This has helped a lot, thanks!
Post Reply