Quote:
|
Originally Posted by Eldarion
One of the things that keeps tripping us up is that the MPLAB compiler does not follow standard C data type promotion rules.
For example, given the statement below, standard C would promote both data types to integer, then multiply. The MPLAB compiler, however, multiplies a and b as unsigned chars and then sticks the result in the integer value, resulting in an overflow where you least expect it!
Code:
unsigned char a = 127:
unsigned char b = 127;
int result;
result = (a * b);
|
You can turn on integer promotions by going to "Project" > "Build Options" > "Project" in MPLAB, clicking the "MPLAB C18" tab, and adding "-Oi " to the beginning of the "Use Alternate Settings" text box. (Checking the "Enable integer promotions" check box will NOT work.) Believe me, I had plenty of trouble with this too!
