Visual Studio 2017 不支持C11 新特性_Generic [英] Visual Studio 2017 does not supportC11 new feature _Generic

查看:87
本文介绍了Visual Studio 2017 不支持C11 新特性_Generic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我为什么 Visual Studio 2017 不支持 C11 新功能 _Generic?我发现这是一个非常有用的功能,但不能在 Visual Studio 2017 中使用.

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.

以下是示例代码:

#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 ==========

推荐答案

Visual Studio 2017 不支持任何 C11 功能.您可以将 Intel C 编译器插入 Visual Studio(支持 C11)或使用 ClangGcc.

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 答案:

  • 向您的 Visual Studio 添加内置的 CLANG 支持
  • 创建新项目
  • 在平台工具集"的项目属性(常规)中选择Visual Studio 2017 - Clang with Microsoft CodeGen (v141_clang_c2)
  • 在C/C++语言"部分打开C语言"标准列表,您将在其中找到当今所有相关的C标准L C89、C99、C11…选择你想要的

此后(与以往一样)VS2017 将编译带有.c"的文件扩展名为 C,.cpp"扩展名为 C++.

After this (same as ever) VS2017 will compile files with ".c" extension as C, and ".cpp" extension as C++.

不要忘记可以在每个文件的基础上更改属性

Do not forget that one can change the properties on the per file basis too.

这篇关于Visual Studio 2017 不支持C11 新特性_Generic的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆