简体   繁体   English

timespec和struct timespec有什么区别?

[英]what is the difference between timespec and struct timespec?

I try to create a code for generating of timestamp. 我尝试创建用于生成时间戳的代码。 I found two different structures, but its not clear what is the difference? 我发现了两种不同的结构,但不清楚有什么区别? Can anybody help me to understand what is the difference between these two structures? 有人可以帮助我了解这两种结构之间的区别吗? struct timespec and timespec now ? timespec now struct timespectimespec now吗?

The following structure: 结构如下:

struct timespec

is provided by the POSIX.1b standard, defined in time.h. 由time.h中定义的POSIX.1b标准提供。 From the GNU libc documentation, 21.2 Elapsed Time : 从GNU libc文档中, 经过时间21.2

Data Type: struct timespec The struct timespec structure represents an elapsed time. 数据类型:struct timespec struct timespec结构表示经过的时间。 It is declared in time.h and has the following members: 它在time.h中声明,并具有以下成员:

long int tv_sec This represents the number of whole seconds of elapsed time. long int tv_sec这表示经过时间的整秒数。

long int tv_nsec This is the rest of the elapsed time (a fraction of a second), represented as the number of nanoseconds. long int tv_nsec这是经过的剩余时间(以秒为单位),以纳秒数表示。 It is always less than one billion. 它总是少于十亿。

If you saw the following: 如果您看到以下内容:

timespec now

Someone probably wrote a typedef for the struct, and "now" would refer to a variable name. 可能有人为该结构编写了一个typedef,“ now”将引用一个变量名。 If you wrote a typedef for the struct, there would be no difference between "struct timespec" and "timespec". 如果您为该结构编写了typedef,则“结构timespec”和“ timespec”之间不会有任何区别。

There are many functions in time.h that can help you. time.h有很多功能可以为您提供帮助。 You can find full documentation here: http://pubs.opengroup.org/onlinepubs/007908775/xsh/time.h.html 您可以在此处找到完整的文档: http : //pubs.opengroup.org/onlinepubs/007908775/xsh/time.h.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM