所以我试着用这段代码作为基准:

#include <time.h>
#include <sys/time.h>
#include <sys/resource.h>

double get_time()
{
    struct timeval t;
    struct timezone tzp;
    gettimeofday(&t, &tzp);
    return t.tv_sec + t.tv_usec*1e-6;
}

但不知什么原因,我一直犯这个错误
error: storage size of ‘tzp’ isn’t known
warning: unused variable ‘tzp’

任何帮助都将不胜感激。

最佳答案

您定义了_XOPEN_SOURCE=500。根据X/Open 5,第二个参数的类型是void*,并且必须是NULL

int gettimeofday(struct timeval *tp, void *tzp);

[..]
如果tzp不是空指针,则行为未指定
如果您想要linux手册中指定的原型,您需要
#define __USE_BSD

但是,如果传递的不是NULL,它将返回一个错误。

关于c - 未知“tzp”的存储大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25483031/

10-12 05:42