Can anybody advise why Visual Studio 2017 does not support the C11 new feature _Generic
? I found it is a very useful feature but cannot used in Visual Studio 2017.
Below is the sample code:
#include <stdio.h>
#define MYTYPE(X) _Generic((X),\
int:"int",\
float:"float",\
double:"double",\
default:"other")
int main(void)
{
int d = 5;
printf("%s\n", MYTYPE(d));
printf("%s\n", MYTYPE(2.0*D));
return 0;
}
The complier will give below warnings and errors:
1>------ Build started: Project: Project1, Configuration: Debug Win32 ------
1>predef.c
1>c:\users\mia\documents\c\listing 16.13\project1\project1\predef.c(11): warning C4013: '_Generic' undefined; assuming extern returning int
1>c:\users\mia\documents\c\listing 16.13\project1\project1\predef.c(11): error C2059: syntax error: 'type'
1>c:\users\mia\documents\c\listing 16.13\project1\project1\predef.c(12): error C2065: 'D': undeclared identifier
1>c:\users\mia\documents\c\listing 16.13\project1\project1\predef.c(12): error C2059: syntax error: 'type'
1>Done building project "Project1.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This is because Microsoft has never prioritized conformance to the C language standard. Over the last 20 years or so, their main focus has been C++. So Visual Studio is to be regarded as a C++ compiler.
In "C mode", it still has questionable compliance towards the first C standard C90. It took them forever to make an attempt to get C99 compliance, they made some effort towards that only in recent years. It is still not fully C99 compliant either. As far as I know, there are no plans for C11 or C17 compliance.
So if standard conformance is important to you, you must look for another C compiler.
Visual Studio 2017 does not support any C11 features. You can plug Intel C compiler into Visual Studio (which supports C11) or use Clang or Gcc.
Quora answer: