title: Converting an unsigned long to 64-bit signed long in C
body: <p>I am trying to return a type jlong (defined in JNI as a signed 64-bit long value) from type DWORDLONG (defined in WIN32 as an unsigned 64-bit int).</p>
  
  <p>Simply type casting:</p>
  
  <pre><code>DWORDLONG dwl = 1000000000000;
  jlong n = (jlong) dwl;
  </code></pre>
  
  <p>changes the value since the operation is undefined.</p>
  
  <p>How then do you convert an unsigned long to a signed long, maintaining the same numeric value it had before?</p>
  
  <p><strong>Update</strong></p>
  
  <p>It appears the issue was happening because of a pointer dereferencing error that slipped through my testing.  The cast was not altering the value.  Thanks to everyone who commented/answered, at least now I know this is a perfectly legal operation.</p>