Which version of C is supported by VS2019 compiler?

女生的网名这么多〃 提交于 2021-02-15 06:14:19

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/57965155/which-version-of-c-is-supported-by-vs2019-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!