WindowsとLinuxで次の関数を使用したいのですが、__int64をunsignedlongに変換する方法がわかりません。私のように値をキャストしても安全ですか?
getTimeInMilliseconds()
{
#ifdef _WIN32
static const __int64 magic = 116444736000000000; // 1970/1/1
SYSTEMTIME st;
GetSystemTime(&st);
FILETIME ft;
SystemTimeToFileTime(&st,&ft); // in 100-nanosecs...
__int64 t;
memcpy(&t,&ft,sizeof t);
return (unsigned long)((t - magic)/10000);
#else
struct timeval tv;
gettimeofday(&tv, NULL);
unsigned long s = tv.tv_sec * 1000;
unsigned long us = tv.tv_usec / 1000;
return s + us;
#endif
}