A repeated value such as 3 can carry different meanings in one program. Naming each meaning makes the code easier to maintain and prevents accidental identification of equal values. section 5.6
char const*const bird[3] = {
"raven",
"magpie",
"jay",
};
char const*const pronoun[3] = {
"we",
"you",
"they",
};
char const*const ordinal[3] = {
"first",
"second",
"third",
};
...
for (unsigned i = 0; i < 3; ++i)
printf("Corvid %u is the %s\n", i, bird[i]);
...
for (unsigned i = 0; i < 3; ++i)
printf("%s plural pronoun is %s\n", ordinal[i], pronoun[i]);
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":10}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":10}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":10}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":10}],[{\"line\":5,\"ch\":5},{\"line\":5,\"ch\":10}],[{\"line\":10,\"ch\":5},{\"line\":10,\"ch\":10}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":10}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":10}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":10}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":10}],[{\"line\":5,\"ch\":5},{\"line\":5,\"ch\":10}],[{\"line\":10,\"ch\":5},{\"line\":10,\"ch\":10}],[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":10}],[{\"line\":5,\"ch\":0},{\"line\":5,\"ch\":10}],[{\"line\":10,\"ch\":0},{\"line\":10,\"ch\":10}],[{\"line\":0,\"ch\":5},{\"line\":0,\"ch\":10}],[{\"line\":5,\"ch\":5},{\"line\":5,\"ch\":10}],[{\"line\":10,\"ch\":5},{\"line\":10,\"ch\":10}],[{\"line\":16,\"ch\":0},{\"line\":16,\"ch\":3}],[{\"line\":19,\"ch\":0},{\"line\":19,\"ch\":3}],[{\"line\":16,\"ch\":5},{\"line\":16,\"ch\":13}],[{\"line\":19,\"ch\":5},{\"line\":19,\"ch\":13}],[{\"line\":17,\"ch\":4},{\"line\":17,\"ch\":10}],[{\"line\":20,\"ch\":4},{\"line\":20,\"ch\":10}],[{\"line\":16,\"ch\":0},{\"line\":16,\"ch\":3}],[{\"line\":19,\"ch\":0},{\"line\":19,\"ch\":3}],[{\"line\":16,\"ch\":5},{\"line\":16,\"ch\":13}],[{\"line\":19,\"ch\":5},{\"line\":19,\"ch\":13}],[{\"line\":17,\"ch\":4},{\"line\":17,\"ch\":10}],[{\"line\":20,\"ch\":4},{\"line\":20,\"ch\":10}]]"}
!@%STYLE%@!
The listing places explanatory names such as bird, pronoun, and ordinal beside related string values, then uses those names in output. section 5.6
TAKEAWAY 1: Constants with a particular meaning must be named. Constants that happen to be equal but mean different things must remain distinguishable. section 5.6
C supplies several ways to approximate or provide named constants:
- Enumeration constants provide C's proper named-constant mechanism. section 5.6
- Macros provide generic text replacement and produce compile-time constants only when replacements use literals of base types. section 5.6
- Temporary objects provide a constant-like approach for more-complicated data types. section 5.6
Name the artifact, not merely the value
Names such as corvid_num, M_PI, false, true, SIZE_MAX, and fortytwo identify constants that stand out because of factual, standard-defined, platform-specific, external, cultural, or design significance. section 9.2


