Warning Message C2705

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Warning Message C2705

Jump to solution
551 Views
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.

Labels (1)
0 Kudos
1 Solution
464 Views
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

View solution in original post

0 Kudos
2 Replies
465 Views
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 Kudos
464 Views
rayhall
Contributor V

Edward,

Thank you.

Ray.

0 Kudos