...
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 | ||||
|---|---|---|---|---|
| ||||
enum { IN_STR_LEN=18, OUT_STR_LEN=20 };
|
...
The declaration in this compliant solution embodies the relationship between the two definitions.
| Code Block | ||||
|---|---|---|---|---|
| ||||
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 | ||||
|---|---|---|---|---|
| ||||
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 | ||||
|---|---|---|---|---|
| ||||
enum { ADULT_AGE=18 };
enum { ALCOHOL_AGE=21 };
|
...