09-05-2016 10:50 AM
Hello all,
I am receving a sequence of 12-bit binary integers from a microprocessor and I want to decode them.
My code is the following:
unsigned short mm1 = 0, mm2 = 0, mm3 = 0; int i; char buf[64]; i = 0; mm1 = (buf[i++] << 8) + buf[i++]; mm2 = (buf[i++] << 8) + buf[i++]; mm3 = (buf[i++] << 8) + buf[i++];
The compiler issues the following: "warning: multiple unsequenced modifications to 'i' ", however returned values are correct (er, they were in CVI2012: I am porting some code to 2015 but still haven't tested it).
What does it means? How can I get rid of the warning?
Solved! Go to Solution.
09-05-2016 11:07 AM
Hello Roberto
It means that the compiler doesn't guarantees the order "++" operation is performed in relation to other access of variable i; That is when the 2nd i++ is executed you are not sure if i was already incremented or it will be incremented twice at the end.
To get rid of the warning you have to split the i++ operations in different instructions.
mm1 = (buf[i++] << 8) ; mm1 += buf[i++];
Related thread: CVI 2013 compiler: increment / decrement operator evaluation
Cosntantin
09-05-2016 03:59 PM - edited 09-05-2016 04:05 PM
Wow, this opens a whole new world of arguments to study!
I can get rid of any ++ operator with the following code that seems to work:
for (i = 0, j = 0; i < 6; j++, i+=2) { mm[j] = (buf[i] << 8) + buf[i + 1]; }