unsigned char x=1; x=(x++)<<3;
x=(++x)<<3; works it gives 16
>Keil does have some problems with the pre- and >post- increment/decrement operators when used >within a more complicated expression Which problems your take in mind ? >(x++)<<3 >is equivalent to >(x)<<3; x += 1 >and it seems that MSVC has the "right" >answer. This is not exactly the same as original qiestion:
unsigned char x = 1; x=(x++) << 3;
unsigned char x = 1; unsigned char tmp; tmp = x; // get old value of 'x' x = x + 1; // x++ x = (tmp << 3); // Assign('=') have lowest priority
Please see http://www.eskimo.com/~scs/C-faq/q3.3.html
x = (x++) << 3;
x = x + 1 << 3;
Mark, thanks for good point: http://www.eskimo.com/~scs/C-faq/q3.3.html http://www.eskimo.com/~scs/C-faq/top.html It is a good place to understand why I intuitively avoid some ambiguous C-constructions :) On the other side, this is a 'style' quiestion. For example, in your case I always write as
x = (x + 1) << 3;
unsigned char x = 1; x = (x++) << 3;
LVALUE = EXPRESSION