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

A new Bug

unsigned char aa,bb,cc,dd;

aa = 0xab;
bb = 0xcd;
cc = (aa+bb)%255; //aa+bb=0x178
dd = (unsigned char)((aa+bb)%255);

when debug, youcan see that the result: cc is 0x78, dd is 0x79. In fact, cc and dd should be 0x79.

I debugged in C51 9.60, 9.03. Both had the same output.

I tried in VC2010, TI CCS3.3, both can get the correct result, 0x79.

Parents
  • I debugged in C51 9.60, 9.03. Both had the same output.

    I'm not using C51 today, but there is a checkbox in Target Options somewhere that alters integer promotion. Change it. The cost will be a bit of code size and potentially speed. Broeker I believe is correct regarding the rules of C versus C51. Also you can typecast and/or user intermediate variables of different types to learn what is happening.

Reply
  • I debugged in C51 9.60, 9.03. Both had the same output.

    I'm not using C51 today, but there is a checkbox in Target Options somewhere that alters integer promotion. Change it. The cost will be a bit of code size and potentially speed. Broeker I believe is correct regarding the rules of C versus C51. Also you can typecast and/or user intermediate variables of different types to learn what is happening.

Children