Other Parts Discussed in Thread: MSP430G2231
I'm working through Lab 7 and I get an "integer conversion resulted in truncation" error. It disappears if I close/open CCS and compiles, but the error reappears if I make ANY change to the program code.
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Other Parts Discussed in Thread: MSP430G2231
I'm working through Lab 7 and I get an "integer conversion resulted in truncation" error. It disappears if I close/open CCS and compiles, but the error reappears if I make ANY change to the program code.
Hi Mike,
Please provide more details. What lab are you referring to? What device are you compiling code for? What version of the compiler are you using? What version of CCS? Attaching a reproducible test case would be very helpful.
Thanks
ki
The message "integer conversion resulted in truncation" generally occurs when there is a statement in the C code that results in truncation due to assigning a larger data type into a smaller one. I believe it is usually a warning, not an error.
Mike K said:It disappears if I close/open CCS and compiles, but the error reappears if I make ANY change to the program code.
When you close/reopen CCS and build the project, it is likely not rebuilding everything because there are no changes. If you specifically did a rebuild (even without making any changes) I would expect that you would see those warnings again.
It's Lab 7. And the code is the code provided in the lab. See the LaunchPad PDF containing the labs ("Getting Started with the MSP430 LaunchPad: Student Guide and Lab Manual"). It's compiled for msp430g2231. CCS version 4.2.3.00004.
The line that causes the warning is:
P2SEL = ~(BIT6 + BIT7);
Which really shouldn't be a warning, since the two bits are OR'd and then flipped. It still results in a byte.
If you look at the macro expansion of BIT6 and BIT7 they are words (0x0040 and 0x0080 respectively) so the result of this expression is actually 0xFF3F. When assigned to the byte P2SEL, the 0xFF is truncated and throws this warning. To remove the warning, simply cast the result to a char:
P2SEL = (char)(~(BIT6 + BIT7));
This tells the compiler that you know there is a truncation, and stops the compiler from throwing the warning.