Warning Message C2705

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Warning Message C2705

跳至解决方案
558 次查看
rayhall
Contributor V

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.

标签 (1)
0 项奖励
1 解答
471 次查看
kef2
Senior Contributor IV

_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

在原帖中查看解决方案

0 项奖励
2 回复数
472 次查看
kef2
Senior Contributor IV

_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

0 项奖励
471 次查看
rayhall
Contributor V

Edward,

Thank you.

Ray.

0 项奖励