title: C / C++ best practices with signed / unsigned ints and function calls
body: <p>I am asking this question for two different languages: C and C++.</p>
  
  <p>What is best practice when calling functions that have an opposite integer sign expectation to what we require in our code?</p>
  
  <p>For example:</p>
  
  <pre><code>uint32       _depth;                        // uint32 = DWORD
  int          depth;
  
  _BitScanForward(&amp;_depth, (uint32)input);    // DWORD, DWORD
  depth = (int)_depth;
  </code></pre>
  
  <p>_BitScanForward is expecting DWORD (uint32) parameters. The variable <code>input</code> is of int16 type and I need to process the result <code>_depth</code> as an int32 in my code.</p>
  
  <ol>
  <li>Do I need to care about casting <code>input</code> as shown? I know the complier will <em>probably</em> do it for me, but what is best practice?</li>
  <li>Is it acceptable to declare <code>_depth</code> as int32 and therefore avoid having to cast it afterwards as shown?</li>
  </ol>
  
  <p><strong>NOTE:</strong></p>
  
  <p>My comment about the complier is based on experience. I wrote code that compiled with no warnings in VS but crashed on execution. Turned out I was calling a function with an incorect width int. So I don't leave this topic up to the compiler any more.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The answers are helpful, thanks. Let me refine my question. If there are no width issues, i.e. the function is not expecting a narrower int than what is being passed in (obvioulsy will fail), then is it okay to rely on the compiler to handle sign and width differences?</p>