title: windows linux timestamping c++ error
body: <p>I am trying to write time stamp code to calculate lag by sending time stamps in milliseconds. The server code runs on linux while the client runs on windows:</p>
  
  <p>The function used to obtain the time stamp is as follows:</p>
  
  <pre><code>uint64_t TimeStamp() {
      uint64_t ll_now;
  #if PLATFORM==PLATFORM_WINDOWS
      FILETIME ft_now; 
      GetSystemTimeAsFileTime(&amp;ft_now);
      ll_now = (uint64_t)ft_now.dwLowDateTime + ((uint64_t)(ft_now.dwHighDateTime) &lt;&lt; 32LL);
      ll_now -= 116444736000000000LL;
      ll_now /= 10000;
  #elif PLATFORM==PLATFORM_LINUX
      timeval end;
      gettimeofday( (timeval*)&amp;end,NULL );
      ll_now=(uint64_t)(end.tv_usec)/1000LL;
      ll_now += ((uint64_t)(end.tv_sec) * 1000LL);
  #endif
      return ll_now;
  }
  </code></pre>
  
  <p>In the client code, the time stamp is packed for sending as follows:</p>
  
  <pre><code>uint64_t tmstamp= TimeStamp();
  uint32_t ts_high=((uint32_t)(tmstamp&gt;&gt;32LL));
  uint32_t ts_low =((uint32_t)(tmstamp &amp; 0xFFFFFFFFLL));
  ts_high=htonl(ts_high);
  ts_low=htonl(ts_low);
  StdOPacket p;
  p&lt;&lt;ts_high&lt;&lt;ts_low;
  </code></pre>
  
  <p>In the server code, the time stamp is unpacked when received as follows:</p>
  
  <pre><code>uint32_t ts_high,ts_low;
  input&gt;&gt;ts_high&gt;&gt;ts_low;
  ts_high=ntohl(ts_high);
  ts_low=ntohl(ts_low);
  uint64_t sndTS=uint64_t(ts_low)+(uint64_t(ts_high)&lt;&lt;32LL);
  uint64_t curTS=TimeStamp();
  int64_t dif=(int64_t)curTS-(int64_t)sndTS;
  std::cout&lt;&lt;"current timestamp: "&lt;&lt;curTS&lt;&lt;std::endl;
  std::cout&lt;&lt;"send timestamp: "&lt;&lt;sndTS&lt;&lt;std::endl;
  std::cout&lt;&lt;"dif: "&lt;&lt;dif&lt;&lt;std::endl;
  </code></pre>
  
  <p>However, when I run the program, the difference is calculated to be approximately -1000(ms), which defies the laws of time?</p>
  
  <p>Note: StdOPacket simply copies given data pointers into a buffer, and StdIPacket copies data from a buffer to a given reference.</p>
  
  <p>EDIT:</p>
  
  <p>Platform definition:</p>
  
  <pre><code>#ifdef _WIN32
  #define PLATFORM PLATFORM_WINDOWS
  #elif defined __linux__
  #define PLATFORM PLATFORM_LINUX
  #else
  #define PLATFORM PLATFORM_UNKOWN
  #endif
  </code></pre>