You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

6.5.16.1 Simple assignment

const char **cpp;
char *p;
const char c = 'A';
cpp = &p; // constraint violation
*cpp = &c; // valid
*p = 'B'; // valid

The first assignment is unsafe because it would allow the following valid code to attempt to change the
value of the const object c. This code compiles without warning on Microsoft Visual C++ .NET (2003) and the resulting program changes the value of c.

6.7.3 Type qualifiers Paragraph 5

If an attempt is made to modify an object defined with a const-qualified type through use
of an lvalue with non-const-qualified type, the behavior is undefined. If an attempt is
made to refer to an object defined with a volatile-qualified type through use of an lvalue
with non-volatile-qualified type, the behavior is undefined.

  • No labels