This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C Question - '=': value truncated

Why does the following code produce a C192: '=': value truncated error? They are all uint8_t's. Structure definition shown below. What is there to truncate, all variables are of the exact same type! The result is correct but I am just interested in why.

msg.DataBuffer[7] = msg.DataBuffer[0] ^ msg.DataBuffer[1] ^ msg.DataBuffer[6];

typedef struct
{ uint16_t CANID; uint8_t DataBuffer[8]; uint8_t DataSize;
} CAN_MESSAGE;

Parents
  • The intermediate result of the XOR operation (as other operations too) has the default data type. If that default data type is larger than the variable size on the left, it must be truncated. However, this should not be an 'error' as you write, it should be a 'warning' only.

Reply
  • The intermediate result of the XOR operation (as other operations too) has the default data type. If that default data type is larger than the variable size on the left, it must be truncated. However, this should not be an 'error' as you write, it should be a 'warning' only.

Children