Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>(Trying to focus on other aspects of the question)</p> <p>The <a href="http://en.wikipedia.org/wiki/Const-correctness#C.2B.2B_syntax" rel="nofollow">rule of thumb for const declarations</a> is to read them from right to left and <code>const</code> modifies the next token. Exception: At the beginning of a declaration <code>const</code> modifies the previous token.</p> <p>There is a <a href="http://carlo17.home.xs4all.nl/cpp/const.qualifier.html" rel="nofollow">rationale behind this exception</a> - for elementary declarations <code>const char c</code> looks for some people more natural than <code>char const c</code> - and it is reported that a precursor form of <code>const char c</code> predates the final const rule.</p> <h2>getopt</h2> <pre><code>int getopt(int argc, char * const argv[], const char *optstring); </code></pre> <p>or</p> <pre><code>int getopt(int argc, char * const * argv, const char *optstring); </code></pre> <p>Which means that <code>argv</code> is a pointer to const vector of pointers to non-const strings.</p> <p>But one would expect following declaration:</p> <pre><code>int getopt(int argc, char const * const * argv, const char *optstring); </code></pre> <p>(pointer to const vector to const strings)</p> <p>Because <code>getopt()</code> is not supposed to change the strings referenced via argv.</p> <p>At least <code>char **</code> (as used in <code>main()</code>) automatically converts to <code>char * const * argv</code>.</p> <h2>Clang</h2> <pre><code>ASTUnit::LoadFromCommandLine(..., const char **argv, ...); </code></pre> <p>Which means that <code>argv</code> is a pointer to a non-const array of pointers to const strings.</p> <p>Again one would expect <code>const char * const *argv</code> for the same reason as above.</p> <p>But this is more noticeable because <code>char **</code> <a href="http://www.parashift.com/c++-faq-lite/const-correctness.html#faq-18.17" rel="nofollow">does not convert</a> to <code>const char **</code>, e.g.</p> <pre><code>int main(int argc, char **argv) { const char **x = argv; // Compile error! return 0; } </code></pre> <p>yields a compile error, where</p> <pre><code>int main(int argc, char **argv) { char * const *x = argv; return 0; } </code></pre> <p>and</p> <pre><code>int main(int argc, char **argv) { const char * const *x = argv; return 0; } </code></pre> <p>do not.</p>
 

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