这段代码有什么问题?
typedef unsigned char datum; /* Set the data bus width to 8 bits. */
datum pattern;
datum antipattern;
antipattern = ~pattern;
Remark[Pa091]: operator operates on value promoted to int (with possibly unexpected result) C:\filepath...\file.c 386 编译器是IAR EWARM,为什么需要将两个char变量转换为int。当所有东西都被声明为未签名时,它为什么要抱怨符号的更改。
你知道该使用什么样的强制转换来消除这个警告吗?
发布于 2013-04-05 23:55:44
C的规则要求将unsigned char操作数转换为int (在逆向C实现中除外)。
一旦操作数是int,它就是有符号的,~操作符可能会给你带来意想不到的结果,因为有符号整数的语义和它们的位表示并不是完全由C指定的。编译器对此给予了有益的警告。
您应该使用antipattern = ~ (unsigned int) pattern;。使用unsigned int,可以保证值是用简单的二进制表示的。
https://stackoverflow.com/questions/15838249
复制相似问题