Hello,
I am getting this warning for some code, and not for other code that are basically the same. "Warning C2750: Possible loss of data"
I can disable the message, but would prefer not to do this. What is wrong ?
TIM_TFLG1 &= ~(1<<TIM_TFLG1_C0F_MASK); // No warning
TIM_TFLG1 &= ~(1<<TIM_TFLG1_C1F_MASK); // No warning
TIM_TFLG1 &= ~(1<<TIM_TFLG1_C2F_MASK); // No warning
TIM_TFLG1 &= ~(1<<TIM_TFLG1_C3F_MASK); // Get Warning C2705
TIM_TFLG1 &= ~(1<<TIM_TFLG1_C4F_MASK); // Get Warning C2705
TIM_TFLG1 &= ~(1<<TIM_TFLG1_C5F_MASK); // No warning
The micro is the S12XE.
Ray.
Solved! Go to Solution.
_MASK at the end tells that it already equals one shifted left by N bit places. Look in H files how those xxx_MASK constants are defined. They all are bit masks and not a bit number.
So
1<<TIM_TFLG1_C0F_MASK == 1<<1 = 2
1<<TIM_TFLG1_C1F_MASK == 1<<2 = 4
1<<TIM_TFLG1_C2F_MASK == 1<<4 = 0x10
1<<TIM_TFLG1_C3F_MASK == 1<<8 = 0x100 , which requires 9 bits and can't fit 8bit TFLG1.
1<< TIM_TFLG1_C4F_MASK == 1<<16 = 0x10000 which requires 17bits
1<< TIM_TFLG1_C5F_MASK == 1<<32 33 bits. Certainly compiler integer constants math is 32bits wide and thus compiler doesn't produce warning for 1<<32
You need to remove erroneous "1<< "
Regards,
Edward
_MASK at the end tells that it already equals one shifted left by N bit places. Look in H files how those xxx_MASK constants are defined. They all are bit masks and not a bit number.
So
1<<TIM_TFLG1_C0F_MASK == 1<<1 = 2
1<<TIM_TFLG1_C1F_MASK == 1<<2 = 4
1<<TIM_TFLG1_C2F_MASK == 1<<4 = 0x10
1<<TIM_TFLG1_C3F_MASK == 1<<8 = 0x100 , which requires 9 bits and can't fit 8bit TFLG1.
1<< TIM_TFLG1_C4F_MASK == 1<<16 = 0x10000 which requires 17bits
1<< TIM_TFLG1_C5F_MASK == 1<<32 33 bits. Certainly compiler integer constants math is 32bits wide and thus compiler doesn't produce warning for 1<<32
You need to remove erroneous "1<< "
Regards,
Edward
Edward,
Thank you.
Ray.