Storage size of timespec isn't known

grizzle picture grizzle · Mar 4, 2017 · Viewed 7.8k times · Source

I have seen this solution but I am getting the same errors. For a class, we had to switch to the c99 compiler instead of gnu but now timespec seems to be broken. Along with "storage size of timespec isn't known", I am getting a bunch of other errors like "CLOCK_MONOTONIC undeclared", "dereferencing a pointer to incomplete type 'struct timespec'", and unused variable warnings but I assume these would go away once I work out the compiler issue.

I wouldn't imagine there is anything wrong with the way I am declaring timespec variables,

struct timespec startTime;

Answer

alk picture alk · Mar 5, 2017

As this kind of "clock" support isn't C99 but POSIX, it's not enabled by default.

To enable it you want to pass the option -D_POSIX_C_SOURCE=199309L to the compiler or put a

#define _POSIX_C_SOURCE 199309L

at very beginning of the source file(s) in question.

See also man clock_gettime for reference.