We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
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
No bugs, only opinions here. For case 1, (10000L/20000L) == 0, thus (value *= 0) == 0. For case 2, the expression is evaluated as (value * 10000L)/20000L, so as long a value is >= 2, the result will be nonzero.
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