Do not cast away a {{Wiki Markup const}} qualification on a variable type. Casting away the {{const}} qualification allows violation of rule \[[EXP31-C. Do not modify constant values]\] prohibiting the modification of constant values.
Non-Compliant Code Example
The remove_spaces() function in this non-compliant code example accepts a pointer to a string str and a string length slen and removes the space character from the string by shifting the remaining characters towards the front of the string. The function remove_spaces() is passed a const char pointer as an argument. The const qualification is cast away ; after which and then the contents of the string are modified.
...
In this compliant solution, the function remove_spaces() is passed a non-const char pointer. The calling function must ensure that the null-terminated byte string passed to the function is not const by making a copy of the string or by other means.
...
Otherwise, do not attempt to modify the contents of the array.
Exceptions
EXP05-EX1: An exception to this rule is allowed when it is necessary to cast away const when invoking a legacy API that does not accept a const argument, provided the function does not attempt to modify the referenced variable. For example, the following code casts away the const qualification of INVFNAME in the call to the log() function.
...