4

How can I know which version of C is supported by the VS2019 compiler? I looked in the project C/C++ and Linker command lines and found no -std=Cxx flag. The following code compiles:

for (int i = index; i < nb_users - 1; i++) {
    users[i] = users[i + 1];
}

So I guess it's C99 according to this, but is there a way to check this somewhere in VS2019?

sepp2k
  • 363,768
  • 54
  • 674
  • 675
evilmandarine
  • 4,241
  • 4
  • 17
  • 40
  • 4
    C89 plus a few bits and pieces of later standards. – Shawn Sep 16 '19 at 22:35
  • What does `printf("%ld\n", __STDC_VERSION__);` report? – chux - Reinstate Monica Sep 17 '19 at 01:26
  • @chux It does not compile, "identifier is undefined". Sorry I'm new in C as you can tell. – evilmandarine Sep 17 '19 at 09:01
  • 3
    `__STDC_VERSION__` wasn't allowed in C90, nor was declaring a variable inside a for loop `for (int i =...`. If you are a newbie, you are much better off throwing VS in the garbage and get a standard C compiler. For example Codeblocks with gcc/mingw compiler, it is a reasonably newbie-friendly Windows toolchain. – Lundin Sep 17 '19 at 09:42
  • 1
    @supafly *It does not compile...* That means VS2019 is not a [C99-compliant compiler](https://port70.net/~nsz/c/c99/n1256.html#6.10.8). – Andrew Henle Sep 17 '19 at 11:25

2 Answers2

3

VS2019 supports ANSI C90 plus a few other features from a few later standards that are required in C++.

For example, you can tell that C99 is not fully supported in MSVC with this code, which will fail to compile:

int foo(int n, char *s)
{
    char s2[n];
    strcpy(s2, s);
    return !strcmp(s, s2);
}

This specific feature (variable-length arrays) is not supported in MSVC, while the feature you mentioned (for loop initial declaration) is.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
1

Which version of C is supported by VS2019 compiler?

At best, C 1989.


A compliant compiler to some C standard is identifiable via the values of __STDC__ __STDC_VERSION__.

#ifndef __STDC__
  printf("Does not ID itself as compliant to any C standard.\n");
#else
  printf("Compliant to some C standard\n");
  #ifndef __STDC_VERSION__
    printf("C 1989\n");
  #else 
    // Expected values of of 2019
    // 199409L
    // 199901L
    // 201112L
    // 201710L
    printf("C %ld\n", __STDC_VERSION__);
  #endif
#endif

I'd expect VS2019 to not identify itself compliant to any C standard or perhaps 1989.

__STDC__ Defined as 1 only when compiled as C and if the /Za compiler option is specified. Otherwise, undefined. Predefined macros


VS2019 not on this incomplete list of C compilers

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256
  • 2
    Indeed, it does not identify itself compliant to any C standard. The `/Za` link in your answer is helpful. – evilmandarine Sep 17 '19 at 21:17
  • Should it be `#elif __STDC__ == 1 printf("Compliant ...");` instead of `#else printf("Compliant ...");`? – pmor Apr 01 '21 at 16:05
  • @pmor Maybe after the `#ifndef __STDC__ printf("Does ...` could as `#elif __STDC__ != 1 printf("Not Compliant");` for a pedantic test - and then go on to the `#else printf("Compliant to some C standard\n");` – chux - Reinstate Monica Apr 01 '21 at 18:10
  • @chux-ReinstateMonica `__STDC__` is defined using "positive logic". Hence, I find logical to use "positive logic" as well: `#if __STDC__ == 1 /* compliant */ #else /* not defined OR defined to != 1 => not compliant */ #endif`. – pmor Apr 01 '21 at 22:26