title: Declaring a pointer to const or a const pointer to const as a formal parameter
body: <p>I was recently making some adjustments to code wherein I had to change a formal parameter in a function.  Originally, the parameter was similar to the following (note, the structure was typedef'd earlier):</p>
  
  <pre><code>static MySpecialStructure my_special_structure;
  static unsigned char char_being_passed;              // Passed to function elsewhere.
  static MySpecialStructure * p_my_special_structure;  // Passed to function elsewhere.
  
  int myFunction (MySpecialStructure * p_structure, unsigned char useful_char)
  {
      ...
  }
  </code></pre>
  
  <p>The change was made because I could define and initialize my_special_structure before compile time and myFunction never changed the value of it.  This led to the following change:</p>
  
  <pre><code>static const MySpecialStructure my_special_structure;
  static unsigned char char_being_passed;              // Passed to function elsewhere.
  static MySpecialStructure * p_my_special_structure;  // Passed to function elsewhere.
  
  int myFunction (const MySpecialStructure * p_structure, unsigned char useful_char)
  {
      ...
  }
  </code></pre>
  
  <p>I also noticed that when I ran Lint on my program that there were several Info 818's referencing a number of different functions.  The info stated that <strong>"Pointer parameter 'x' (line 253) could be declared as pointing to const"</strong>.</p>
  
  <p>Now, I have two questions in regards to the above.  First, in regards to the above code, since neither the pointer nor the variables within MySpecialStructure is changed within the function, is it beneficial to declare the pointer as constant as well?  e.g. -</p>
  
  <pre><code>int myFunction (const MySpecialStructure * const p_structure, unsigned char useful_char)
  </code></pre>
  
  <p>My second question is in regards to the Lint information.  Are there any benefits or drawbacks to declaring pointers as a constant formal parameter if the function is not changing its value... even if what you are passing to the function is never declared as a constant?  e.g. -</p>
  
  <pre><code>static unsigned char my_char;
  static unsigned char * p_my_char;
  p_my_char = &amp;my_char;
  
  int myFunction (const unsigned char * p_char)
  {
      ...
  }
  </code></pre>
  
  <p>Thanks for your help!</p>
  
  <p><strong>Edited for clarification -</strong></p>
  
  <p>What are the advantages of declaring a <strong>pointer to <code>const</code></strong> or a <strong><code>const</code> pointer to <code>const</code></strong>- <strong>as a formal parameter</strong>? I know that I <em>can</em> do it, but why would I want to... particularly in the case where the pointer being passed and the data it is pointing to are not declared constant?</p>