4

C11 標準 (7.27.2.5) によると、 でtimespec_get指定された機能がありますtime.h。C11をサポートするはずのclangやいくつかのバージョンのgccなど、いくつかのコンパイラを試しましたが、この機能は常に欠落しています。マクロTIME_UTCも欠落しています。

テストファイルは次のmytime.cとおりです。

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

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
      [-Wimplicit-function-declaration]
  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.

timespec_getC11を使用していることを確認するために、この行をコメントアウトしました。

gcc バージョン 4.8、5、および 6 で基本的に同じ結果が得られます。

Mac、OS 10.11.6 を使用しています。

4

2 に答える 2