Why isn't timespec_get defined on any C compiler on my Mac?

According to the C11 Standard (, there is a function timespec_get specified in time.h. I have tried several compilers, including clang and several versions of gcc, which are supposed to support C11, but this function is always missing. The macro TIME_UTC is also missing.

Here is a test file mytime.c:

#include <time.h>
#include <stdio.h>
int main() {
  printf("C version: %ld\n", __STDC_VERSION__);
  struct timespec ts;
  timespec_get(&ts, TIME_UTC);

and the output using Clang:

$ cc --version
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ cc -std=c11 mytime.c
mytime.c:9:3: warning: implicit declaration of function 'timespec_get' is invalid in C99
  timespec_get(&ts, TIME_UTC);
mytime.c:9:21: error: use of undeclared identifier 'TIME_UTC'
  timespec_get(&ts, TIME_UTC);
1 warning and 1 error generated.

I commented out the timespec_get line just to make sure I am using C11, and I am.

I get basically the same results for gcc versions 4.8, 5, and 6.

I am using a Mac, OS 10.11.6.


  • The Mac OS X standard library does not conform to any modern version of C or POSIX. It is stuck at C99 and POSIX 2001 and has conformance problems even with respect to these.