Result of logic operation on 8-bits data need to casts
Hello,
In STVD (+Cosmic) C compiler settings I choose *Display Errors & Warnings*.
I wrote simple code:
uint8_t a=0x01;
uint8_t b=0x10;
void test (uint8_t licz) {
}
void main (void) {
test (a & 0x01);
test (a | b);
test (a + b);
}
After compilation there are warnings:
#warning cpstm8 main.c:122(9) truncating assignment
#warning cpstm8 main.c:123(9) truncating assignment
#warning cpstm8 main.c:124(10) truncating assignment
To avoid warnings I need to use casts, for example:
test ((uint8_t)(a & 0x01));
The result of (a + b) operation do not exceed max value 8-bit long data.
Why are there warnings?
All data are declared as 8-bits long.
If the data will be declared as integer 16-bits long there’s no need to use casts.