35

I know that compilers use __STDC__ to indicate that a compiler is standard C and, from, there, you can use __STDC_VERSION__ to figure out which level of the standard you're using.

I also know that C90 had no value, C90 amendment 1 had 199401L and C99 had 199901L.

The latest C1x draft I have simply states it as 201ymmL and I'm assuming it was made a less "vague" value in the final standard.

My guess is that it will be 201112L since that's when C11 was ratified but I'd like to be certain.

I thought I could try using gcc -std=c1x but the version of gcc I'm running doesn't support that yet.

Does anyone know what the actual value is?

Charles
  • 50,943
  • 13
  • 104
  • 142
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • 1
    In any case the numbering of C versions is sufficiently coarse such that you can just test for `> 201100L`. – Jens Gustedt Feb 15 '12 at 14:14
  • Duplicate: [What is C11 cor 1:2012?](https://stackoverflow.com/questions/13914050/what-is-c11-cor-12012). – Lundin Sep 27 '19 at 08:36
  • Lundin: have closed the dupe. – paxdiablo Sep 27 '19 at 09:26
  • @paxdiablo Yeah well... neither you nor me were suitable for doing that (closing a post as a dupe with our own post as target), since we are partial. The linked one isn't a dupe of this though, but the other way around, since the TC contained other things than `__STDC_VERSION__` as well. – Lundin Sep 27 '19 at 10:27
  • As an addendum for anyone looking, the value for C17 is `201710L`. – Toby Dec 31 '21 at 17:32

2 Answers2

34

With -std=c11 in gcc, 201112L is used for __STDC_VERSION__

See this gcc patch on December 20, 2011 on gcc ml:

https://www.mail-archive.com/gcc-patches@gcc.gnu.org/msg23572.html

And note that apparently the ISO version of C11 forgot to update the 201ymmL from the Draft.

The intended final __STDC_VERSION__ value, 201112L, is also implemented (the editor forgot to update the 201ymmL placeholders before sending the document for publication by ISO).

See also DR #411, which makes it official that the intended value is 201112l. The editor has said that "The committee is trying to get it approved as a TC as soon as possible.". (TC = "Technical Corrigendum")

EDIT (July 16, 2012): Technical Corrigendum 1 (ISO/IEC 9899:2011/Cor 1:2012) released on July 15, 2012 fixes the __STDC_VERSION__ to 201112L.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
ouah
  • 142,963
  • 15
  • 272
  • 331
  • Which version of gcc is that? My Ubuntu 1104 one is 4.5.2 and I'll be stuffed if I'm upgrading to 1110, given the fact I've heard that hideous Unity interface is no longer optional :-) – paxdiablo Feb 15 '12 at 13:32
  • 1
    it seems that `-std=c11` has been added to `gcc` 4.7 http://gcc.gnu.org/gcc-4.7/changes.html – ouah Feb 15 '12 at 13:35
  • @paxdiablo: you can get rid of Unity, but since the patch was submitted Dec 20, it wasn't in Ubuntu 11.10. – Fred Foo Feb 15 '12 at 13:36
  • Oh well, I guess I'll wait for 1204 and hope that Shuttleworth et al come to their senses :-) – paxdiablo Feb 15 '12 at 13:37
  • 4
    I have the final ISO version and I can confirm that they have forgotten to change it. It still says "201ymmL" just as in the draft. – Lundin Feb 15 '12 at 14:35
  • 1
    ISO released a corrigendum yesterday 2012-07-15 *Cor 1:2012* for C11: value `__STDC_VERSION__` is now fixed to `201112L` http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=61717 – ouah Jul 16 '12 at 12:42
2

According to this post to the GCC mailing list, the final value is, as you suspected, 201112L.

Dan Moulding
  • 211,373
  • 23
  • 97
  • 98