この方法でキャストできますか?
int clockOffset;
clockOffset=((int64_t)Time_1_delayed-Time_1-Time_2_delayed+Time_2)/2;
ここで、すべての時間変数はuint
です。
署名済みの結果を に入れたいclockOffset
。
Cでできることは次のとおりです(intとunsignedintがlonglongよりも短いと仮定):
#include <limits.h>
...
unsigned int Time_1_delayed, Time_1, Time_2_delayed, Time_2;
...
long long diff = ((long long)Time_1_delayed - Time_1 - Time_2_delayed + Time_2) / 2;
int clockOffset;
if (diff < INT_MIN || diff > INT_MAX)
HandleTheError();
clockOffset = diff;
...