4

This is from my terminal:

Korays-MacBook-Pro:~ koraytugay$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix

There are 3 C standards as far as I know, ANSI C, C99 and C11.

How can I know which library I have and what my compiler supports?

alk
  • 69,737
  • 10
  • 105
  • 255
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
  • possible duplicate of http://stackoverflow.com/questions/17206568/what-is-the-difference-between-c-c99-ansi-c-and-gnu-c-a-general-confusion-reg EDIT: sorry, that only explains the differences between the standards – mstbaum Apr 13 '15 at 15:53

3 Answers3

4

Clang support all three standards and more (“gnu99” from GCC, …). You can find out in the documentation of the commandline option -std which is used to choose them.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
  • You just beat me to it, ++ – Shafik Yaghmour Apr 13 '15 at 15:55
  • My compiler can not find so I think I either do not have the C11 library or my compiler does not support it? – Koray Tugay Apr 13 '15 at 15:59
  • @KorayTugay It should be noted that while the C standards describe **compilation platforms** in which standard libraries and compiler per se are not distinguished (and indeed it would be harmful to try to), the Open Source world insists on treating them as distinct projects. I could give you more examples: compiler translation of struct assignment as memcpy calls (not valid with strict standard memcpy implementations), floating-point rounding mode stuff (that the compiler should be aware of to be correct and cannot be left to the library), … – Pascal Cuoq Apr 13 '15 at 16:04
  • 1
    @KorayTugay see [C11 GCC threads.h not found?](http://stackoverflow.com/q/22875545/1708801) – Shafik Yaghmour Apr 13 '15 at 16:59
4

http://clang.llvm.org/docs/UsersManual.html#id39

Use the -std command-line flag, e.g. -std=c11 or -std=c++11 to select the standard.

pts
  • 80,836
  • 20
  • 110
  • 183
4

You have to find the documentation for your compiler and/or operating system and it's not always clearly documented.


Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)

This corresponds to Xcode 6.3.

https://developer.apple.com/library/mac/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html

Also anything in the LLVM 3.5 release should be in this version of the compiler: the compiler is 'based on the llvm 3.6 svn branch, which exists prior to LLVM.org's 3.6 release (a bit confusing, I know).

http://clang.llvm.org/cxx_status.html

They don't have a similar handy page for C version support, however.

http://llvm.org/releases/3.5.0/tools/clang/docs/UsersManual.html#differences-between-various-standard-modes

In fact it looks to me like the documentation doesn't even accurately reflect clang 3.5's C11 support.


So basically, if the documentation doesn't clearly cover it, you just have to be familiar with the compiler.

Xcode 6.3 supports C language features for C89/C90, C94, C99, and C11. I believe OS X offers full library support up to C99. OS X does not include an implementation of the C11 standard library, however some C11 headers may be provided by the compiler. <threads.h> isn't, however.

bames53
  • 86,085
  • 15
  • 179
  • 244
  • @alk One of the ISO documents was released in 1994 (there were also updates in 1995 and 1996). I've never bothered with it, but the [documentation](http://llvm.org/releases/3.5.0/tools/clang/docs/UsersManual.html#differences-between-various-standard-modes) says it's supported. However it seems like this might be another inaccuracy in the docs, since clang gives an error for `-std=c94`. – bames53 Apr 13 '15 at 16:31
  • Oh I see. And looking up the gcc docs reveals that the argument to `-std` shall be `iso9899:199409` for this then, which obviously isn't commonly known (anymore) ... :-)) – alk Apr 13 '15 at 16:37
  • Interesting, that works for clang too, but the clang docs say to use `c94`. – bames53 Apr 13 '15 at 16:39
  • 1
    Here's the source for the full list of language modes supported by the current version of clang: http://llvm.org/svn/llvm-project/cfe/trunk/include/clang/Frontend/LangStandards.def – bames53 Apr 13 '15 at 16:55
  • @alk: C94 is probably C90 with corrections and ammendment AMD1, which added the wide char functions. – ninjalj Jun 03 '15 at 19:53