Versions Compared

Key

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

Wiki Markup
Do not cast away a {{const}} qualification on a variable type. Casting away the {{const}} qualification will allow violation of rule \[[EXP31-C. Do not modify constant values ]\] prohibiting the modification of constant values.

...

Code Block
bgColor#FFcccc
void remove_spaces(const char const *str, size_t slen) {
   char *p = (char*)str;
   size_t i;
   for (i = 0; i < slen && str[i]; i++) {
      if (str[i] != ' ') *p++ = str[i];
   }
   *p = '\0';
}

...

In this example, a const int array vals is declared and its content modified by memset() with the function, clearing the contents of the vals array.

Code Block
bgColor#FFcccc
const int const vals[] = {3, 4, 5};
memset(vals, 0, sizeof(vals));

...

Code Block
void log(char *errstr) {
  fprintf(stderr, "Error: %s.\n", errstr);
}

/* ... */
const char const INVFNAME[]  = "Invalid file name.";
log((char *)INVFNAME);
/* ... */

...

Wiki Markup
\[[ISO/IEC 9899-1999|AA. C References#ISO/IEC 9899-1999]\] Section 6.7.3, "Type qualifiers"