timespec和struct timespec有什么区别?

时间:2015-03-07 13:40:28

标签: c time timespec

我尝试创建用于生成时间戳的代码。我发现了两种不同的结构,但不清楚有什么区别?任何人都可以帮我理解这两种结构之间的区别吗? struct timespectimespec now

1 个答案:

答案 0 :(得分:1)

以下结构:

struct timespec

由POSIX.1b标准提供,在time.h中定义。从GNU libc文档21.2 Elapsed Time

  

数据类型:struct timespec   struct timespec结构表示经过的时间。它在time.h中声明,并具有以下成员:

     

long int tv_sec   这表示经过时间的整秒数。

     

long int tv_nsec   这是剩余的经过时间(几分之一秒),表示为纳秒数。它总是不到十亿。

如果您看到以下内容:

timespec now

有人可能为结构编写了一个typedef,现在"现在"会引用变量名称。如果你为struct编写了一个typedef,那么" struct timespec和#34;之间没有区别。和" timespec"。

time.h中有许多功能可以帮到你。您可以在此处找到完整的文档:http://pubs.opengroup.org/onlinepubs/007908775/xsh/time.h.html

相关问题