This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
Hi CCS champion,
My customer reported a compiler question about left *** use case, please help to look into:
uint16_t a = 0;
uint32_t b = 0;
uint32_t c = 0;
uint32_t d = 0;
main{
....
a = 0x10;
b = 0x55;
d = (uint32_t)a<<16 -b; // get wrong result 0x80000000
if(d==0)
d =1;
a = 0x10;
b = 0x55;
c = (uint32_t)a<<16; // correct 0x00100000
d = c - b; // get correct result 0x000FFFAB
if(d==0)
d=1;
....
}
If change the equation as d = (uint32_t)(a<<16) -b;, it work fine.
I checked the disassembly code, the previous one used LSLL, while correct one use LSL.
Please give your comments of this case.
Thank you!
In C, subtraction has higher precedence than shifting, so the expression "(uint32_t)a<<16-b" is equivalent to "((uint32_t)a)<<(16-b)".