2

What is the STDC_VERSION value for C11? asks about C11, and How can I use "nullptr" for null pointers prior to C23? says that the current versions of GCC and Clang define it to a placeholder value 202000L.

GCC 14 Release Series Changes, New Features, and Fixes has now added the std=c23 flag, but doesn't mention what __STDC_VERSION__ expands to.

2 Answers 2

5

From N3220:

__STDC_VERSION__ The integer constant 202311L

popular name edition constant
C23 fifth 202311L
C17/18 fourth 201710L
C11 third 201112L
C99 second 199901L
C?? first, amendment 1 199409L

It was in the first edition, amendment 1, to C89/90 where the addition of the predefined __STDC_VERSION__ macro was made. I'm unsure if it goes by any popular name but C94/95 has been suggested.

6
  • 1
    For Normative Amendment 1 to the 1990 C standard, Wiki suggests the informal name of C95. I have also seen C94 and C94/95. Commented Jun 5 at 15:52
  • @chux-ReinstateMonica Great, thanks! I made a rough edit (I'm on the phone right now).
    – Ted Lyngmo
    Commented Jun 5 at 16:00
  • 1
    Nice. I prefer C94 as many years from now all we care about (date-wise) is 199409L and not its official release date. Same for C17 with its 201710L Commented Jun 5 at 16:07
  • 1
    Fortunately, the name C94 or C95 and its value for __STDC_VERSION__ are very rarely relevant these days. Commented Jun 5 at 18:18
  • 3
    GCC 14.1.0 is documented as supporting -std=X where the values for X include iso9899:1990, iso9899:199409, iso9899:1999, iso9899:2011 iso9899:2017, iso9899:2018 and (c23 or) iso9899:2024. AFAIK, ISO has still not actually published C23. I'm not sure what the hold-up is. The committee is working towards C26. Commented Jun 5 at 18:27
3

Empirically, GCC 14.1.0 still prints the placeholder version number 202000 when compiling with -std=c23 or -std=iso9899:2024:

#include <stdio.h>
int main(void)
{
    printf("__STDC_VERSION__ = %ld\n", __STDC_VERSION__);
    return 0;
}

Compiling and executing:

$ gcc --version
gcc (GCC) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ gcc -O cv67.c -o cv67 && cv67
__STDC_VERSION__ = 201710
$ gcc -O -std=c23 cv67.c -o cv67 && cv67
__STDC_VERSION__ = 202000
$ gcc -O -Wall -Werror -Wextra -std=iso9899:2024 cv67.c -o cv67 && cv67
__STDC_VERSION__ = 202000
$ gcc -O -Wall -Werror -Wextra -std=iso9899:2011 cv67.c -o cv67 && cv67
__STDC_VERSION__ = 201112
$ gcc -O -Wall -Werror -Wextra -std=iso9899:1999 cv67.c -o cv67 && cv67
__STDC_VERSION__ = 199901
$ gcc -O -Wall -Werror -Wextra -std=iso9899:199409 cv67.c -o cv67 && cv67
__STDC_VERSION__ = 199409
$ gcc -O -Wall -Werror -Wextra -std=iso9899:1990 cv67.c -o cv67 && cv67
cv67.c: In function ‘main’:
cv67.c:4:40: error: ‘__STDC_VERSION__’ undeclared (first use in this function)
    4 |     printf("__STDC_VERSION__ = %ld\n", __STDC_VERSION__);
      |                                        ^~~~~~~~~~~~~~~~
cv67.c:4:40: note: each undeclared identifier is reported only once for each function it appears in
$

So GCC 14.1.0 defaults to C17/C18, and uses __STDC_VERSION__ == 202000 for C23.

5
  • So a check for __STDC_VERSION__ >= 202311L with the std=c23 flag in GCC 14.1 would evaluate to false? I checked Clang 18.1's documentation and it stated that it uses 202311L for C23. GCC's behavior is strange.
    – Harith
    Commented Jun 5 at 18:41
  • 1
    @Harith — Correct! But #if __STDC_VERSION > 201710L would evaluate to true. Commented Jun 5 at 18:43
  • 2
    Searching on the ISO web site today for 9899 (the C standard number) suggests that you might be able to buy the DIS (draft international standard) for CHF 129 (Swiss Francs). OTOH, you (or your organization) might need to be a member of ISO — the page says "This Draft International Standard is in the enquiry phase with ISO members". Commented Jun 5 at 18:46
  • 1
    A draft version from 2024 is available at port70.net/~nsz/c/c23/n3220.pdf A 2022 draft can be found at iso-9899.info/n3047.html Commented Jun 5 at 22:07
  • The way I've gone about this is to write error reports if what's expected isn't happening. MS was very very reluctant at first but I was just one of many who wanted their preprocessor macros to behave very close to what you'd expect - and it's a lot better now. It's not all the way there, but, much better.
    – Ted Lyngmo
    Commented Jun 5 at 22:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.