Versions Compared

Key

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

...

In this noncompliant code example, the definition for OUT_STR_LEN must always be two greater than the definition of IN_STR_LEN. The following definitions fail to embody this relationship:

Code Block
bgColor#FFcccc
langc
enum { IN_STR_LEN=18, OUT_STR_LEN=20 };

...

The declaration in this compliant solution embodies the relationship between the two definitions.

Code Block
bgColor#ccccff
langc
enum { IN_STR_LEN=18, OUT_STR_LEN=IN_STR_LEN+2 };

...

In this noncompliant code example, a relationship is established between two constants where none exists.

Code Block
bgColor#FFcccc
langc
enum { ADULT_AGE=18 };

/* misleading, relationship established when none exists */
enum { ALCOHOL_AGE=ADULT_AGE+3 };

...

This compliant solution does not assume a relationship when none exists:

Code Block
bgColor#ccccff
langc
enum { ADULT_AGE=18 };
enum { ALCOHOL_AGE=21 };

...