Reputation: 33
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
?
Upvotes: 1
Views: 2111
Reputation: 150
The following structure:
struct timespec
is provided by the POSIX.1b standard, defined in time.h. From the GNU libc documentation, 21.2 Elapsed Time:
Data Type: struct timespec The struct timespec structure represents an elapsed time. It is declared in time.h and has the following members:
long int tv_sec This represents the number of whole seconds of elapsed time.
long int tv_nsec This is the rest of the elapsed time (a fraction of a second), represented as the number of nanoseconds. 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. If you wrote a typedef for the struct, there would be no difference between "struct timespec" and "timespec".
There are many functions in time.h that can help you. You can find full documentation here: http://pubs.opengroup.org/onlinepubs/007908775/xsh/time.h.html
Upvotes: 2