Versions Compared

Key

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

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
bgColor#ffcccc
langc
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
bgColor#ccccff
langc
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

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

CC2.DCL15

Fully implemented

LDRA tool suite

Include Page
LDRA_V
LDRA_V

27 D
61 D
553 S

Fully implemented

PRQA QA-C
Include Page
PRQA_V
PRQA_V

1504
1505

Fully implemented

Splint

Include Page
Splint_V
Splint_V

 

 

...

Bibliography

ISO/IEC 9899:2011Section Subclause 6.2.2, "Linkages of Identifiers"

...