AnsweredAssumed Answered

Result of logic operation on 8-bits data need to casts

Question asked by h007 on May 16, 2017
Latest reply on May 18, 2017 by luca

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.

Outcomes