Topic : Integer type casting

Forum : ST7/STM8

Original Post
Post Information Post
December 6, 2010 - 4:23pm
Guest

Hi,

What does STM8 compiler do if I assign an unsigned integer variable's value to a signed integer variable and if the unsigned variable's value is out of the boundaries of signed value? I couldn't find any information in the compiler manual. An example is below.

unsigned int u16_variable1;
signed int s16_variable2;

...
u16_variable1 = 65535;
s16_variable2 = u16_variable1;

if(s16_variable2 < 0)
;//do process 1
else
;//do process 2
...

Thanks&Regards

Replies
Post Information Post
+1
0
-1
December 7, 2010 - 9:06am
Raisonance Support Team

Hi Volkan,

Our Compiler is strictly ISO C compliant. This means that the "upward conversion" is applied whenever necessary (on binary and ternary operators). In your example, u16 is bitwise-copied into s16, which will lead to a "-1" value for s16.

Best Regards,