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

2020-02-08 09:16发布

if(a || b || c || d),可用,但不明白它为什么警告,这样做到底可不可行。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
16条回答
mplk
1楼-- · 2020-02-09 19:15
照12楼的说法,我之前处理CHAR型标志位也只是让它为0或者1,看来是不会有太大问题的,只是警告而已。
millwood0
2楼-- · 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.

mplk
3楼-- · 2020-02-09 23:13
millwood0 发表于 2012-4-22 22:21
true. and it is an incredibly risky / counter-intuitive convention.

that means the following two  ...

PICC果然变态,哈哈,以后还真得多加小心。
usk5yenj4id04dm
4楼-- · 2020-02-10 01:14
shandian 发表于 2012-4-22 21:45
在此处,对于一般的C编译器来说,我觉得用||和|效果应该是一样的。只是内部处理顺序不同。||是先把char类 ...

这怎么可能是一样的呢?

一周热门 更多>