Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: small changes for consistency

...

Code Block
void foo(int x) {
  x = 3; /* visibleVisible only in the function. */
  /* ... */
}

Pointers behave in a similar fashion. A function may change a pointer to reference a different object, or NULL, yet that change is discarded once the function exits. Consequently, declaring a pointer as const is unnecessary.

Code Block
void foo(int *x) {
  x = NULL; /* Visible only in the function. */
  /* ... */
}

Noncompliant Code Example

...

Code Block
bgColor#FFCCCC
langc
void foo(int *x) {
  if (x != NULL) {
    *x = 3; /* visibleVisible outside function. */
  }
  /* ... */
}

If the function parameter is const-qualified, any attempt to modify the pointed-to value should cause the compiler to issue a diagnostic message.

Code Block
bgColor#ffcccc
langc
void foo(const int *x) {
  if (x != NULL) {
    *x = 3; /* compilerCompiler should generate diagnostic message. */
  }
  /* ... */
}

As a result, the const violation must be resolved before the code can be compiled without a diagnostic message being issued.

...