首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

C语言clock()函数最多只能表示20多天的有关问题

2012-10-11 
C语言clock()函数最多只能表示20多天的问题C语言clock()计算的是从进程运行到该函数调用经过的时间,返回值

C语言clock()函数最多只能表示20多天的问题
C语言clock()计算的是从进程运行到该函数调用经过的时间,返回值是long型.一般情况下32位系统,CLOCKS_PER_SEC为1000. long最多只能表示24.8天,那么24.8天以后呢?我写的服务器程序需要计算延时的时间间隔精确到毫秒,如果不用clock函数,有其他方法实现吗?

[解决办法]
Because the beginning of the std::clock era does not have to coincide with the start of the program, only the difference between two values returned by different calls to std::clock is meaningful.

C/C++ code
//溢出也能正常工作long lapseInSecond = 0;std::clock_t last = clock();while(run) //定期检查{   //...  std::clock_t  current = clock();  lapseInSecond += (current - last) / CLOCKS_PER_SEC;  last = current;}
[解决办法]
time()函数

热点排行