VS2019编译器支持哪个版本的C?

Which version of C is supported by VS2019 compiler?

如何知道VS2019编译器支持哪个版本的C?我查看了项目 C/C++ 和链接器命令行,没有发现 -std=Cxx 标志。以下代码编译:

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

所以我猜测根据this它是C99,但是有没有办法在VS2019的某个地方检查这个?

VS2019 支持 ANSI C90 以及 C++ 所需的一些后来的标准中的一些其他功能。

例如,您可以使用这段代码判断 C99 在 MSVC 中不完全支持,将无法编译:

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

MSVC 不支持此特定功能(可变长度数组),而您提到的功能(for 循环初始声明)支持。

Which version of C is supported by VS2019 compiler?

最好是 C 1989。


通过 __STDC__ __STDC_VERSION__.

的值可以识别符合某些 C 标准的编译器
#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

我预计 VS2019 不会表明自己符合任何 C 标准或 1989。

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


VS2019不在这incomplete list of C compilers