The timespec comes from POSIX, so you have to 'enable' POSIX definitions:
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif /* __STDC_VERSION__ */
#include <time.h>
void blah(struct timespec asdf)
{
}
int main()
{
struct timespec asdf;
return 0;
}
The stanza at the top is what I currently use - it triggers the definitions from Single UNIX Specification (SUS) based on whether you're using a C99 or C89 compiler.
- If you want the POSIX 2008 (SUS v4) material, use _XOPEN_SOURCE 700
- If you want the POSIX 2004 (SUS v3) material, use _XOPEN_SOURCE 600
- If you want the POSIX 1995 (SUS v2, 1997) material, use _XOPEN_SOURCE 500
For my systems, POSIX 2008 is not as widely available as 2004, so that's what I use - but YMMV. Note that SUS v3 and v4 both require C99 compilation. On Solaris, at least, using C89 will fail.