Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Although this noncompliant code example compiles correctly, it is unlikely that it means what the author of the code intended.:

Code Block
bgColor#FFcccc
langc
int a = 2;
int b = 2;
int c = 2;
/* ... */
if (a < b < c) /* misleading, likely bug */
/* ... */
if (a == b == c) /* misleading, likely bug */

...

Treat relational and equality operators as if it were invalid to chain them.:

Code Block
bgColor#ccccff
langc
if ( (a < b) && (b < c) ) /* clearer, and probably what was intended */
/* ... */
if ( (a == b) && (a == c) ) /* ditto */

...

Tool

Version

Checker

Description

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

exprprns

Fully implemented.

GCC

Include Page
GCC_V
GCC_V

 

Option -Wparentheses warns if a comparison like x<=y<=z appears. This ; this warning is also enabled by -Wall.

PRQA QA-C
Include Page
PRQA_V
PRQA_V

3392
3401
4111
4112
4113

Fully implemented.

Related Guidelines

Bibliography

[ISO/IEC 9899:2011]Section 6.5.8, "Relational Operators"

 

...