2

この方法でキャストできますか?

int clockOffset;

clockOffset=((int64_t)Time_1_delayed-Time_1-Time_2_delayed+Time_2)/2;

ここで、すべての時間変数はuintです。

署名済みの結果を に入れたいclockOffset

4

2 に答える 2

1

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;
...
于 2013-02-07T15:29:05.360 に答える