...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <iostream> struct S { int i; S(int i) : i(i) {} }; void g(volatile S &s) { std::cout << s.i << std::endl; } void f() { volatile S s(12); g(s); } |
Exceptions
EXP35EXP55-CPP-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. It is always preferable to modify the API to be const
-correct when possible, however. For example, the following code casts away the const
qualification of INVFNAME
in the call to the audit_log()
function.
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
Related Guidelines
SEI CERT C Coding Standard | EXP05-C. Do not cast away a const qualification EXP40-C. Do not modify constant objects |
...