☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

不应重复使用一元运算符

10.3.10 ID_repeatedUnaryOperators
目录 › next › previous

重复的一元运算符没有意义,为常见笔误。

示例:

int a = 1;
int b = ~~a;    // Non-compliant
int c = -+a;    // Non-compliant
int d = - -a;   // Non-compliant

例外:

bool e = !!a;   // Let it go

两个连续的 ! 是 bool 转换的惯用方法,可不受本规则约束。

Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.