Tool/software: TI C/C++ Compiler
Hello,
I'm using Code Composer 8.3.0.9 and compiler TI v16.9.6.LTS.
I've implemented the following function:
void ApplGetParamInfo(unsigned short dataA, unsigned short dataB)
{
unsigned long dataC;
/* DataA is cast from word (16 bits) to long (32 bits);
Data A is masked and left-shifted by 8 bit;
DataB is masked;
DataA and DataB are composed together with a bitwise OR and the result is assigned to dataC
*/
dataC = ((((unsigned long)dataA) & 0x0000FFFFUL) << 8) | (dataB & 0x00FF);
/* Other stuff */
}
If I have
dataA = 0x1234;
dataB = 0x0056;
I get
dataC = 0x00003456;
while I expect to get
dataC = 0x00123456;
In other words, the least significant byte of the more significant word is lost as if the operation has been executed on 16-bit data instead of 32-bit data. I use the cast operation in order not to lose that byte!
I've tried also with this instruction
dataC = ((((unsigned long)dataA) & 0x0000FFFFUL) << 8) | (((unsigned long)dataB) & 0x00FF);
but the result is the same.
Is this a compiler bug?
Thank you in advance.