PICC18下 if(a || b || c || d)编译后出现警告,这种写法可取么?

2020-02-08 09:16发布

if(a || b || c || d),可用,但不明白它为什么警告,这样做到底可不可行。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
17条回答
millwood0
2020-02-09 20:47
在转换为bit的时候不是按照非零则为1的规律来处理的,而只是取了最低位作为运算的bit位。


true. and it is an incredibly risky / counter-intuitive convention.

that means the following two pieces of code:
  1. unsigned char a_ch;
  2. unsigned char t_bit;

  3. if (a_ch) a_ch=SOMETHING;
复制代码and
  1. unsigned char a_ch;
  2. unsigned char t_bit;

  3. t=a_ch;
  4. if (t) a_ch=SOMETHING;
复制代码will yield totally different execution.

If you look at some of the better compilers, you will notice that most of they don't have a (native) bitfield type. Boolean types are usually implemented as char or int.

For that reason, I do not use any bit types in my code.

一周热门 更多>