STM32 ------ 处理 int64 类型数据需要注意

 

uint64_t destime, oritime, rectime, tratime;
int64_t result;

result = ((rectime-oritime) + (tratime-destime))/2;

 

 

当((rectime-oritime) + (tratime-destime))是负数的时候,result不能得到正确的数,需要写成如下:

uint64_t destime, oritime, rectime, tratime;
int64_t result, tmp;

tmp = ((rectime-oritime) + (tratime-destime));
result = tmp/2;

 

posted @ 2020-04-30 16:43  流水灯  阅读(2325)  评论(0编辑  收藏  举报