The C23 timespec_getres() function reports the resolution associated with a supported time base. With TIME_UTC, the result describes the granularity of calendar-time readings.
The function stores the resolution in a struct timespec when the destination is not NULL. It is new in C23, so compiler and library support may lag behind language-mode support. Include <time.h>.
Syntax
Start with this concrete timespec_getres() call:
C
timespec_getres(&resolution, TIME_UTC);
Call
What it does
timespec_getres(&resolution, TIME_UTC);
Stores the resolution of TIME_UTC in resolution.
Declare the required objects with the time types shown below, include <time.h>, and check the documented result before using output data.
Library declaration
C
int timespec_getres(struct timespec *ts, int base);
Parameters
Parameter
Description
ts
Pointer to a writable resolution object; C23 permits NULL when only support is queried.
base
Time base whose resolution is requested, normally TIME_UTC.
Return Value
Return Value
Description
TIME_UTC
The base is supported and its resolution was queried.
0
The requested base is unsupported.
C Examples
Example 1 — Query TIME_UTC Resolution
This example demonstrates timespec_getres() with a small, complete program and checks the relevant result before using it.