title: Const correctness for value parameters
body: <p>I know there are few question about const correctness where it is stated that the declaration of a function and its definition do not need to agree for value parameters. This is because the constness of a value parameter only matters inside the function. This is fine:</p>
  
  <pre><code>// header
  int func(int i);
  
  // cpp
  int func(const int i) {
      return i;
  }
  </code></pre>
  
  <p>Is doing this really a best practice? Because I've never seen anyone do it. I've seen this quotation (not sure of the source) in other places this has been discussed:</p>
  
  <blockquote>
    <p>"In fact, to the compiler, the function signature is the same whether you include this const in front of a value parameter or not."</p>
    
    <p>"Avoid const pass-by-value parameters in function declarations. Still make the parameter const in the same function's definition if it won't be modified."</p>
  </blockquote>
  
  <p>The second paragraph says to not put the const in the declaration. I assume this is because the constness of a value parameter is meaningless as part of a interface definition. It is an implementation detail.</p>
  
  <p>Based on this recommendation, is it also recommended for the pointer values of pointer parameters? (It is meaningless on a reference parameter since you can't reassign a reference.)</p>
  
  <pre><code>// header
  int func1(int* i);
  int func2(int* i);
  
  // cpp
  int func1(int* i) {
      int x = 0;
  
      *i = 3; // compiles without error
      i = &amp;x; // compiles without error
  
      return *i;
  }
  int func2(int* const i) {
      int x = 0;
  
      *i = 3; // compiles without error
      i = &amp;x; // compile error
  
      return *i;
  }
  </code></pre>
  
  <p><strong>Summary:</strong> Making value parameters is useful to catch some logic errors. Is it a best practice? Do you go to the extreme of leaving the const out of the header file? Is it just as useful to const pointer values? Why or why not?</p>
  
  <p><strong>Some references:</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/1554750/c-const-keyword-use-liberally">C++ const keyword - use liberally?</a>
  <a href="https://stackoverflow.com/questions/117293/use-of-const-for-function-parameters">Use of &#39;const&#39; for function parameters</a></p>
  
  <p>An example of when const value parameters are useful:</p>
  
  <pre><code>bool are_ints_equal(const int i, const int j) {
      if (i = j) { // without the consts this would compile without error
          return true;
      } else {
          return false;
      }
      // return i = j; // I know it can be shortened
  }
  </code></pre>