unsigned char x=1; x=(x++)<<3;
x=(++x)<<3; works it gives 16
See "The C Programming Language", second edition, section 2.12. K&R have quite a lot to say about this sort of problem including: "One unhappy situation is typified by the statement
a[i] = i++;
This thread is well and truly dead, but I've found another situation where an ambiguity similar to this can trip you up:
a[b++] = c;
Welcome to the wonderful club comprised of those bitten by race conditions. We'll get you your membership card tomorrow. In point of fact, there doesn't need to be an index in this expression to cause a problem. Essentially, if you have interrupt-driven code, you must imagine that any instruction that is not "atomic" (i.e. completed without interruption) can be stopped in the middle. Thus, something as simple as
a = b;
This ambiguity is actually rather unrelated to the one discussed here earlier. The earlier examples had much more serious problems than yours --- they produced undefined behaviour, which means the compiler is allowed to explode the processor 123*pi hours after noon of the Tuesday following last year's Hallowe'en, if it so pleases. Your example is broken only because introduced an additional ingredient into the game: multiple (pseudo-)concurrent threads of control. C doesn't even try to address that type of problem in the language itself, beyond controlling access to individual objects via the volatile qualifier.