title: idiomatic C for const double-pointers
body: <p>I am aware that in C you can't implicitly convert, for instance, <code>char**</code> to <code>const char**</code> (c.f. <a href="http://c-faq.com/ansi/constmismatch.html" rel="nofollow noreferrer">C-Faq</a>, <a href="https://stackoverflow.com/questions/1624371/pointer-to-const-conversion-in-c">SO question 1</a>, <a href="https://stackoverflow.com/questions/2220916/why-isnt-it-legal-to-convert-pointer-to-pointer-to-non-const-to-a-pointer-to-p">SO Question 2</a>).</p>
  
  <p>On the other hand, if I see a function declared like so:</p>
  
  <pre><code>void foo(char** ppData);
  </code></pre>
  
  <p>I must assume the function may change the data passed in.
  Therefore, if I am writing a function that will <strong>not</strong> change the data, it is better, in my opinion, to declare:</p>
  
  <pre><code>void foo(const char** ppData);
  </code></pre>
  
  <p>or even:</p>
  
  <pre><code>void foo(const char * const * ppData);
  </code></pre>
  
  <p>But that puts the users of the function in an awkward position.
  They might have:</p>
  
  <pre><code>int main(int argc, char** argv)
  {
      foo(argv); // Oh no, compiler error (or warning)
      ...
  }
  </code></pre>
  
  <p>And in order to cleanly call my function, they would need to insert a cast.</p>
  
  <p>I come from a mostly C++ background, where this is less of an issue due to C++'s more in-depth const rules.</p>
  
  <p>What is the idiomatic solution in C?</p>
  
  <ol>
  <li><p>Declare foo as taking a <code>char**</code>, and just document the fact that it won't change its inputs? That seems a bit gross, esp. since it punishes users who might have a <code>const char**</code> that they want to pass it (now they have to cast <strong>away</strong> const-ness)</p></li>
  <li><p>Force users to cast their input, adding const-ness.</p></li>
  <li><p>Something else?</p></li>
  </ol>