gpt4 book ai didi

MacOS 上的 clock_gettime

转载 作者:太空宇宙 更新时间:2023-11-04 03:25:28 25 4
gpt4 key购买 nike

clock_gettime 不再适用于 MacOS Sierra。很确定在 Xcode 8 出来之前我已经正确地编译了这个。我真的很困惑如何才能让它正确编译。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include <time.h>

int main(){
struct timespec time1, time2;

clock_gettime(CLOCK_MONOTONIC,&time1);
//Some code I am trying to work out performance of...
clock_gettime(CLOCK_MONOTONIC,&time2);
printf("Time Taken: %ld",time2.tv_nsec - time1.tv_nsec);
}

像这样的代码根本无法编译。我被告知 sierra 计时库已经改变。我收到一个编译器错误,因为 CLOCK_MONOTONIC 没有被定义,还有一个关于 clock_gettime 隐式声明的警告,如果我将 CLOCK_MONOTONIC 定义为一些随机的东西,因为它只是在链接阶段出错。

有谁知道让代码编译和执行的修复或解决方法?

最佳答案

我不认为 CLOCK_MONOTONIC 最近出现过。

我相信您想要的可能是mach_absolute_time() 加上一个转换,如记录here ;这似乎是单调的和绝对的(您可能知道这是两种不同的东西)。

其他有用的提示可以在以下相关(但我认为不是重复的)问题中找到:

关于MacOS 上的 clock_gettime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41509505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com