Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe the problem is the constraints specified in <em>C99</em> <strong>6.5.16.1(1)</strong>, which seem to prohibit mixing qualifications in assignments, except for pointers for which an inclusive-qualifier exception is defined. The problem is that with indirect pointers, you end up passing a pointer to one thing to a pointer to another. The assignment isn't valid because, if it was, you could fool it into modifying a const-qualified object with the following code:</p> <pre><code>const char **cpp; char *p; const char c = 'A'; cpp = &amp;p; // constraint violation *cpp = &amp;c; // valid *p = 0; // valid by itself, but would clobber c </code></pre> <p>It might seem reasonable that <code>cpp</code>, which promises not to modify any <code>char</code>s, might be assigned a pointer to an object pointing at non-qualified <code>char</code>s. After all, that's allowed for single-indirect pointers, which is why, e.g., you can pass a mutable object to the second parameter of <code>strcpy(3)</code>, the first parameter to <code>strchr(3)</code>, and many other parameters that are declared with <code>const</code>.</p> <p>But with the indirect pointer, at the next level, assignment from a qualified pointer is allowed, and now a perfectly unqualified pointer assignment will clobber a qualified object. </p> <p>I don't immediately see how a 2-D array could lead to this situation, but in any case it hits the same constraint in the standard. </p> <p>Since in your case, you aren't actually tricking it into clobbering a const, the right thing for <em>your</em> code would seem to be inserting the cast.</p> <hr> <p><strong>Update:</strong> OK guys, as it happens this issue is <strong><a href="http://c-faq.com/ansi/constmismatch.html" rel="noreferrer">in the C faq</a></strong>, and this entire discussion has also taken place several times <strong><a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20230" rel="noreferrer">on the gcc bug list</a></strong> and on the gcc mailing list. </p> <ul> <li>Gcc bug list: <strong><a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20230" rel="noreferrer">http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20230</a></strong>.</li> <li>C FAQ: it's question 11.10: <strong><a href="http://c-faq.com/ansi/constmismatch.html" rel="noreferrer">http://c-faq.com/ansi/constmismatch.html</a></strong></li> </ul> <p>The lesson: you can pass a <code>T *x</code> when <code>const T *x</code> is expected, by explicit exception, but <code>T *x</code> and <code>const T *x</code> are still distinct types, so you can't pass a pointer to either one to a pointer to the other.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload