Changes between Version 10 and Version 11 of const


Ignore:
Timestamp:
Oct 30, 2013, 12:48:19 AM (10 years ago)
Author:
andersk@mit.edu
Comment:

Make it clearer why foo **const foo ** would be bad

Legend:

Unmodified
Added
Removed
Modified
  • const

    v10 v11  
    1616`foo *` may be implicitly converted to `const foo *`, but not the other way around.
    1717
    18 `foo **` may be implicitly converted to `foo *const *` (as a special case of the above), but may ''not'' be converted to `const foo **` (otherwise, you could write through `const foo *p` as follows: `foo *q; const foo **pq = &q; *pq = p; *q = …;`).
     18`foo **` may be implicitly converted to `foo *const *` (as a special case of the above), but may ''not'' be converted to `const foo **` (otherwise, you would not be protected from writing to `const foo f`, as follows: `foo *p; const foo **pp = &p; *pp = &f; *p = …;`).
    1919
    2020However, it is safe to convert `foo **` to `const foo *const *`.  C++ lets you do this implicitly (conv.qual 4 in the standard); for no particular reason, C does not.