If a file-scope object or a function does not need to be visible outside of the file, it should be hidden by being declared as static. This practice creates more modular code and limits pollution of the global name space.
Section Subclause 6.2.2 of the C Standard [ISO/IEC 9899:2011] states:
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
enum { MAX = 100 };
int helper(int i) {
/* performPerform some computation based on i */
}
int main(void) {
size_t i;
int out[MAX];
for (i = 0; i < MAX; i++) {
out[i] = helper(i);
}
/* ... */
}
|
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
enum {MAX = 100};
static int helper(int i) {
/* performPerform some computation based on i */
}
int main(void) {
size_t i;
int out[MAX];
for (i = 0; i < MAX; i++) {
out[i] = helper(i);
}
/* ... */
}
|
...
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| CC2.DCL15 | Fully implemented | |||||||
| 27 D | Fully implemented | |||||||
| PRQA QA-C |
| 1504 | Fully implemented | ||||||
|
|
|
...
Bibliography
| ISO/IEC 9899:2011 | Section Subclause 6.2.2, "Linkages of Identifiers" |
...