volatile unsigned int Wi; Wi= (0x4000*3)/(0x10); //The compliler will make Wi = 0xfc00 !! //The right answere is Wi = 0x0c00!!
This is not bug. Keil defaults int operations and int represetation of numbers. After 0x4000*3 the int overflows to 0xc000, which is -0x4000, (-16384 in decimal) . after /10 the result is -1024 in decimal which is 0xfc00.
Keil defaults int operations and int represetation of numbers Actually, that's an ANSI specification. So, all C compilers with 16-bit int types should do this. Jon
There's a possible loophole in this argument though, which might explain the OP's bewilderment: 0x4000 is signed int alright. A constand of 0xb000, however, is unsigned in 16-bit ANSI C compilers. Getting this right might require the "apply ANSI integer promotions" switch of C51 to be active.
"Getting this right might require the "apply ANSI integer promotions" switch of C51 to be active." Or simply being explicit: 0x4000U
View all questions in Keil forum