你好,
在STVD(+ Cosmic)C编译器设置中,我选择* Display Errors&警告*。
我写了简单的代码:
uint8_t a = 0x01;
uint8_t b = 0x10;
void test(uint8_t licz){
}
void main(void){
test(a& 0x01);
测试(a | b);
测试(a + b);
}
编译后有警告:
#warning cpstm8 main.c:122(9)截断赋值
#warning cpstm8 main.c:123(9)截断赋值
#warning cpstm8 main.c:124(10)截断赋值
为了避免警告,我需要使用强制转换,例如:
test((uint8_t)(a& 0x01));
(a + b)操作的结果不超过最大值8位长数据。
为什么会有警告?
所有数据都声明为8位长。
如果数据将被声明为整数16位长,那么就不需要使用强制转换。
以上来自于谷歌翻译
以下为原文
Hello,
In STVD (+Cosmic) C compiler set
tings 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.