timespec not found in time.h

timespec is a struct, you need to explicitly tell the compiler this. If you carefully read the man page you can see it is stated so.

This should work:

#include <time.h>

int main(void) {
    struct timespec TS;
    TS.tv_nsec = 1;

    return 0;
}

Additional note: If it had been defined as a typedef struct, you would not have needed to add the struct part manually. But, you should assume that most/all pure C structs are not defined as a typedef


It should not be just timespec as timespec is a struct. It should be struct timespec. Please modify your code accordingly.

Tags:

C

Struct