title: Why certain implicit type conversions are safe on a machine and not on an other?? How can I prevent this cross platform issues?
body: <p>I recently found a bug on my code that took me a few hours to debug.</p>
  
  <p>the problem was in a function defined as:</p>
  
  <pre><code>unsigned int foo(unsigned int i){
     long int v[]={i-1,i,i+1} ;
         .
         .
         .
   return x ; // evaluated by the function but not essential how for this problem.
  }
  </code></pre>
  
  <p>The definition of v didn't cause any issue on my development machine (ubuntu 12.04 32 bit, g++ compiler), where the unsigned int were implicitly converted to long int and as such the negative values were correctly handled. </p>
  
  <p>On a different machine (ubuntu 12.04 64 bit, g++ compiler) however this operation was not safe. When i=0, v[0] was not set to -1, but to some weird big value (as it often happens
  when trying to make an unsigned int negative).</p>
  
  <p>I could solve the issue casting the value of i to long int</p>
  
  <pre><code>long int v[]={(long int) i - 1, (long int) i, (long int) i + 1};
  </code></pre>
  
  <p>and everything worked fine (on both machines).</p>
  
  <p>I can't figure out why the first works fine on a machine and doesn't work on the other.</p>
  
  <p>Can you help me understanding this, so that I can avoid this or other issues in the future?    </p>