Struct timespec
struct timespec is a C structure type representing a time value with integral seconds and a fractional nanosecond component.
Modern C, Third Edition
struct timespec is a C structure type representing a time value with seconds and a nanosecond component.
- How it is used
- Represents time values when the one-second granularity of time_t is insufficient.
- How deep it goes
- Defines the two fields and their value ranges, then connects the type to acquisition, resolution, and difference operations.
- Examples
- Uses a declaration listing tv_sec and tv_nsec, plus timespec_get and timespec_getres function prototypes.
- What you can do after
- Apply it via timespec_get to obtain nanosecond-precision time values and implement portable differences between them.
Modern C
struct timespec is a C structure type that represents a time interval or timestamp with integral seconds and fractional nanoseconds.
- How it is used
- Represents timestamps or intervals when second-level time_t precision is insufficient.
- How deep it goes
- Defines nanosecond precision and timespec_get usage, but does not explain representation or arithmetic internals.
- Examples
- Uses a timespec_get declaration and contrasts wall-clock, monotonic, and processor-time clocks.
- What you can do after
- Operate timespec_get with TIME_UTC to obtain a timestamp containing nanosecond precision.
Related concepts
- timespec_getused by · timespec_get is a C standard library function that obtains calendar time for a specified time base and stores it in a struct timespec object.
- longhas part · A long is a language-designated integer type whose precision, range, and representation are defined by the language or implementation.
- structkind of · A struct is a composite data type or structure that groups related fields or values into a single unit.
- time_thas part · time_t is an implementation-defined C arithmetic type used to represent calendar time or elapsed-time values.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

