Quote:
|
Originally Posted by Orborde
At any rate, the problem is in the bolded lines. They don't seem to be getting executed at all. I've checked it several times and it still doesn't seem to do it. Now, the elbow control works fine despite this, but it still worries me. I can only guess that those few lines are being "optimized" away for some reason by mcc18. I even put the same function into another development environment and tested it, and it worked as expected. What gives?
|
May I ask HOW you know that these lines are NOT being executed? Could it be that they are executing, but simply not doing what you are expecting?
I can spot several chances for errors in this code. First: >>3 works great for positive numbers, but will only give you headaches if the number you're shifting is negative. (I'm almost positive.

I'll leave it as an exercise for the student to demonstrate yea or nay.)
Second, if you're expecting the lines in questions to only do something when output is between -6 and +6 (as your comment seems to indicate that you might), you're wrong!
Third, if output starts out between -6 and -1, it will first have 7 subtracted from it, and then immediately have 7 added back in!
Do any of those sound like it might explain the behavior/symptom you're seeing?