在的timespec不time.h中找到 [英] timespec not found in time.h

查看:440
本文介绍了在的timespec不time.h中找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不必重写从C ++到C的应用我使用在Ubuntu 12.04 gcc和Eclipse的。在这方面,我所遇到的这个错误

I am having to rewrite an application from C++ to C. I am using gcc and Eclipse on Ubuntu 12.04. In doing so I have come across this error

    ../src/TTNoddy.c: In function ‘main’:
    ../src/TTNoddy.c:16:2: error: unknown type name ‘timespec’

下面是我的code片段,重现问题

Here is my code snippet that reproduces the problem

    #include <time.h>

    int main(void) {

        timespec TS;
        TS.tv_nsec = 1;

        return 0;
    }

我在这里感到困惑 - 我是一个C ++ codeR从不写在我的生活中纯粹的C应用程序,但该男子页 clock_gettime 清楚地表明,的timespec 在我这里包括了time.h中头文件中找到。有什么我错过了??

I am confused here - I am a C++ coder and never written a pure C application in my life, but the man page for clock_gettime clearly indicates that timespec is found in the time.h header file which I am including here. What have I missed??

推荐答案

的timespec是一个结构,你需要明确地告诉编译器这一点。如果你仔细阅读man页面,您可以看到它是这么说。

timespec is a struct, you need to explicitly tell the compiler this. If you carefully read the man page you can see it is stated so.

这应该工作:

#include <time.h>

int main(void) {
    struct timespec TS;
    TS.tv_nsec = 1;

    return 0;
}

补充说明:如果它已被定义为 typedef结构,你就不会需要添加手动结构部分。但是,你应该假设大多数/所有纯C结构没有定义为的typedef

Additional note: If it had been defined as a typedef struct, you would not have needed to add the struct part manually. But, you should assume that most/all pure C structs are not defined as a typedef

这篇关于在的timespec不time.h中找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆