title: C type casting with "const" keyword
body: <p>I usually use C type casting in C/C++ code. My question is, does adding the "const" keyword in the casting type mean anything to the result?</p>
  
  <p>For example, I can think up several scenarios:</p>
  
  <pre><code>const my_struct *func1()
  {
     my_struct *my_ptr = new my_struct;
  
     // modify member variables
  
     return (const my_struct *)my_ptr;
     // return my_instance;
  }
  </code></pre>
  
  <p>In this one, the function constructs a new instance of a struct, and casting it to to a constant pointer, therefore caller will not be able to further modify its internal state except deleting it. Is the "const" casting required, recommended, or simply unnecessary, since either return statement works.</p>
  
  <p>In this one, <code>my_base</code> is the base class of <code>my_derive</code>.</p>
  
  <pre><code>const my_base *func2(const my_derive *my_ptr)
  {
      return (const my_base *)my_ptr;
      // return (my_base *)my_ptr;
  }
  </code></pre>
  
  <p>Since <code>my_ptr</code> is already a const pointer, would casting it with <code>(my_base *)</code> involve a const_cast for removing const and another implicit const_cast when returning?</p>
  
  <p>Is there any reason to add "const" to an integer function argument, since changing it never affect state outside the function?</p>
  
  <pre><code>void func3(const int i)
  {
      // i = 0; is not allowed, but why, as it is harmless?
  }
  </code></pre>
  
  <p>How about adding "const" when casting an integer? I think this should resemble <code>func2()</code>.</p>
  
  <pre><code>void func4(short i)
  {
      const unsigned int j = (const unsigned int) i;
      // const unsigned int j = (unsigned int) i;
  }
  </code></pre>
  
  <p>Correct me if I'm wrong. Considering type casting might be an FAQ, I'm not sure if this one duplicates with anything else. Thanks!</p>