在通过MacPorts安装必要的库后编译我在Mac OS X上编写的程序时,我收到此错误:
In function 'nanotime':
error: 'CLOCK_REALTIME' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)
它似乎clock_gettime没有在Mac OS X中实现.是否有另一种方法可以在纳秒内获得纪元时间?不幸的是在几微秒内.gettimeofday
如何在C中获得微秒时间戳?
我正在尝试:
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_usec;
Run Code Online (Sandbox Code Playgroud)
但是这会返回一些无意义的值,如果我得到两个时间戳,第二个可以比第一个更小或更大(第二个应该总是更大).是否可以将gettimeofday返回的魔术整数转换为可以实际使用的正常数字?