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

Constant folding

HI I'm new to the tread.

I found when using V7.06 constant folding does not appear to work the way I would expect.

I would expect that both of these expressions would evaluate to the same answer. However case 1 results in 0.

Any options, or is this just a bug!
-Jim

unsigned short value;

value = ADC;
value *= 10000L/20000L; //case 1
value = value * 10000L/20000L; //case 2

Parents
  • Any options, or is this just a bug!

    It's a bug in your expectations. The two assignment statements you present aren't really the same. To make the second one equivalent to the first, you'ld have to write

    value = value * (10000L/20000L); //case 2 

    Those parentheses make a very important difference.

Reply
  • Any options, or is this just a bug!

    It's a bug in your expectations. The two assignment statements you present aren't really the same. To make the second one equivalent to the first, you'ld have to write

    value = value * (10000L/20000L); //case 2 

    Those parentheses make a very important difference.

Children
No data