Error C: lvalue required as unary operand &

I have a code error, but I'm not sure what happened to my casting and link.

BOOL xMBPortSerialPutByte( CHAR ucByte ) { CDC_Send_DATA(&((unsigned char)ucByte), 1); // code error here xMBPortEventPost(EV_FRAME_SENT); return TRUE; } 

CDC_Send_DATA is defined as:

 uint32_t CDC_Send_DATA (uint8_t *ptrBuffer, uint8_t Send_length); 

Here is the error message:

  port/portserial.c:139:19: error: lvalue required as unary '&' operand 

Hope someone can help. Thanks!

+4
source share
1 answer

A cast operation produces a transformation giving the value of r. Rvalue has no address, so you cannot use it with unary & . You need to take the address and then drop it:

 CDC_Send_DATA((unsigned char *)&ucByte, 1); 

But, to be most correct, you should probably match the type of arguments in the translation:

 CDC_Send_DATA((uint8_t *)&ucByte, 1); 

Checking the return value is probably also a good idea.

+10
source

Source: https://habr.com/ru/post/1501550/


All Articles