This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C Problem?

unsigned char x=1;
x=(x++)<<3;

Using uVision 6.12
Gives answer of 8
It shifts binary 1 left and doesn't increment.
(even when optimization set to level 0)

Using Micorsoft C++ 6.0
Gives answer of 9
It shifts binary 1 left then increments.


I was a little confused with both answers because I was thought that
the increment would happen first because of the ( ) around x++ then
shift left three giving 16 but that's not the case.

This gives me 16 in both Keil and MS.
x=(++x)<<3; works it gives 16


Parents
  • Actually, there is no need to use the &ltpre&gt and &lt/pre&gt tags for URLs at all - the forum automatically makes URLs clickable (as it says in the Tips).

    It seems that it's this automatic conversion to a link which has gone wrong - it's caught the closing &lt/pre&gt tag inside the closing &lt/a&gt link tag!
    So yes, a space (or newline?) before the &lt/pre&gt would probably have fixed it.

Reply
  • Actually, there is no need to use the &ltpre&gt and &lt/pre&gt tags for URLs at all - the forum automatically makes URLs clickable (as it says in the Tips).

    It seems that it's this automatic conversion to a link which has gone wrong - it's caught the closing &lt/pre&gt tag inside the closing &lt/a&gt link tag!
    So yes, a space (or newline?) before the &lt/pre&gt would probably have fixed it.

Children
No data