Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: wordsmithing

...

Code Block
bgColor#ffcccc
langc
void my_memset(char p[n], size_t n, char v)
{
  memset( p, v, n);
}

Compliant Solution (

...

GCC)

This compliant solution uses a GNU extension to forward declare the size_t variable n before using it in the subsequent array declaration. Consequently, this code allows the existing parameter order to be retained and successfully documents the relationship between the array parameter and the size parameter.

Code Block
bgColor#ccccff
langc
void my_memset(size_t n; char p[n], size_t n, char v)
{
  memset(p, v, n);
}

Compliant Solution (

...

API change

...

)

This compliant solution changes the function's API by moving the size_t variable n to before the subsequent array declaration. Consequently, this code complies with the C99 standard and successfully documents the relationship between the array parameter and the size parameter, but requires all callers to be updated.

...