Visual Studio 是否支持新的 C/C++ 标准?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/146381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:12:42  来源:igfitidea点击:

Visual Studio support for new C / C++ standards?

c++visual-studiovisual-c++c++11c99

提问by Colen

I keep reading about C99 and C++11 and all these totally sweet things that are getting added to the language standard that might be nice to use someday. However, we currently languish in the land of writing C++ in Visual Studio.

我一直在阅读有关 C99 和 C++11 以及所有这些正在添加到语言标准中的完全甜蜜的东西,这些东西有一天可能会很好用。但是,我们目前在 Visual Studio 中编写 C++ 的土地上苦苦挣扎。

Will any of the new stuff in the standard ever get added to visual studio, or is Microsoft more interested in adding new C# variants to do that?

标准中的任何新内容是否会被添加到 Visual Studio,或者微软是否对添加新的 C# 变体更感兴趣?

Edit: In addition to the accepted answer, I found the Visual C++ team blog:

编辑:除了已接受的答案,我还找到了 Visual C++ 团队博客:

http://blogs.msdn.com/vcblog/

http://blogs.msdn.com/vcblog/

And specifically, this post in it:

具体来说,其中的这篇文章:

http://blogs.msdn.com/vcblog/archive/2008/02/22/tr1-slide-decks.aspx

http://blogs.msdn.com/vcblog/archive/2008/02/22/tr1-slide-decks.aspx

Very useful. Thanks!

很有用。谢谢!

回答by jakobengblom2

MS has a series of public replies to this, most of them blaming their users. Like this one:

MS对此有一系列公开回复,其中大部分都指责他们的用户。像这个:

https://devblogs.microsoft.com/cppblog/iso-c-standard-update/

https://devblogs.microsoft.com/cppblog/iso-c-standard-update/

Now, the Visual C++ compiler team receives the occasionally question as to why we haven't implemented C99. It's really based on interest from our users. Where we've received many requests for certain C99 features, we've tried to implement them (or analogues). A couple examples are variadic macros, long long, __pragma, __FUNCTION__, and __restrict. If there are other C99 features that you'd find useful in your work, let us know! We don't hear much from our C users, so speak up and make yourselves heard

现在,Visual C++ 编译器团队偶尔会收到关于为什么我们没有实现 C99 的问题。这实际上是基于我们用户的兴趣。在我们收到许多对某些 C99 特性的请求的地方,我们已经尝试实现它们(或类似物)。几个例子是可变参数宏long long__pragma__FUNCTION__、 和__restrict。如果您发现其他 C99 功能对您的工作有用,请告诉我们!我们从 C 用户那里听到的消息不多,所以说出来,让自己被听到

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=345360

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=345360

Hi: unfortunately the overwhelming feadback we get from the majority of our users is that they would prefer that we focus on C++-0x instead of on C-99. We have "cherry-picked" certain popular C-99 features (variadic macros, long long) but beyond this we are unlikely to do much more in the C-99 space (at least in the short-term).

Jonathan Caves

Visual C++ Compiler Team.

嗨:不幸的是,我们从大多数用户那里得到的压倒性反馈是,他们更愿意我们专注于 C++-0x 而不是 C-99。我们已经“精选”了某些流行的 C-99 特性(可变参数宏long long),但除此之外,我们不太可能在 C-99 领域做更多的事情(至少在短期内)。

乔纳森·凯夫斯

Visual C++ 编译器团队。

This is a pretty sad state of affairs, but also makes sense if you suspect MS wants to lock users in: it makes it very hard to port modern gcc-based code into MSVC, which at least I find extremely painful.

这是一个非常可悲的状态,但如果您怀疑 MS 想要锁定用户,这也是有道理的:将现代基于 gcc 的代码移植到 MSVC 中变得非常困难,至少我觉得这非常痛苦。

A workaround exists, though: Note that Intel is much more enlightened on this. the Intel C compiler can handle C99 code and even has the same flags as gcc, making it much easier to port code between platforms. Also, the Intel compiler works in visual studio. So by scrapping MS COMPILER you can still use the MS IDE that you seem to think has some kind of value, and use C99 to your hearts content.

但是,存在一种解决方法:请注意,英特尔对此更加开明。英特尔 C 编译器可以处理 C99 代码,甚至具有与 gcc 相同的标志,从而更容易在平台之间移植代码。此外,英特尔编译器在 Visual Studio 中工作。因此,通过废弃 MS 编译器,您仍然可以使用您认为具有某种价值的 MS IDE,并尽情使用 C99。

A more sensible approach is honestly to move over to Intel CC or gcc, and use Eclipse for your programming environment. Portability of code across Windows-Linux-Solaris-AIX-etc is usually important in my experience, and that is not at all supported by MS tools, unfortunately.

更明智的方法是转向 Intel CC 或 gcc,并在您的编程环境中使用 Eclipse。在我的经验中,代码在 Windows-Linux-Solaris-AIX 等之间的可移植性通常很重要,不幸的是,MS 工具根本不支持这一点。

回答by paercebal

Herb Sutter is both the chair and a very active member of C++ standardisation comitee, as well as software architect on Visual Studio for Microsoft.

Herb Sutter 是 C++ 标准化委员会的主席和非常活跃的成员,也是 Visual Studio for Microsoft 的软件架构师。

He is among the author of the new C++ memory model standardised for C++0x. For example, the following papers:

他是为 C++0x 标准化的新 C++ 内存模型的作者之一。例如,以下论文:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2669.htm
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2197.pdf

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2669.htm
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007 /n2197.pdf

have his name on it. So I guess the inclusion on Windows of C++0x is assured as long as H. Sutter remains at Microsoft.

上面有他的名字。所以我想只要 H. Sutter 留在微软,就可以保证 C++0x 包含在 Windows 中。

As for C99 only partly included in Visual Studio, I guess this is a question of priorities.

至于 C99 只部分包含在 Visual Studio 中,我想这是一个优先级的问题。

  • Most interesting C99 features are already present in C++ (inlining, variable declaration anywhere, // comments, etc.) and probably already usable in C in Visual Studio (If only doing C code within the C++ compiler). See my answer herefor a more complete discussion about C99 features in C++.
  • C99 increases the divergence between C and C++ by adding features already existing in C++, but in an incompatible way (sorry, but the booleancomplex implementation in C99 is laughable, at best... See http://david.tribble.com/text/cdiffs.htmfor more information)
  • The C community on Windows seems non-existent or not important enough to be acknowledged
  • The C++ community on Windows seems too important to be ignored
  • .NET is the way Microsoft wants people to program on Windows. This means C#, VB.NET, perhaps C++/CLI.
  • 最有趣的 C99 特性已经出现在 C++ 中(内联、任何地方的变量声明、// 注释等),并且可能已经可以在 Visual Studio 的 C 中使用(如果只在 C++ 编译器中执行 C 代码)。见我的答案在这里的一个更完整的讨论在C ++约C99功能。
  • C99 通过添加 C++ 中已经存在的功能来增加 C 和 C++ 之间的分歧,但以不兼容的方式(抱歉,但C99 中的布尔复数实现是可笑的,充其量...见http://david.tribble.com/ text/cdiffs.htm了解更多信息)
  • Windows 上的 C 社区似乎不存在或不重要到需要承认
  • Windows 上的 C++ 社区似乎太重要了,不容忽视
  • .NET 是微软希望人们在 Windows 上编程的方式。这意味着 C#、VB.NET,也许是 C++/CLI。

So, would I be Microsoft, why would I implement features few people will ever use when the same features are already offered in more community active languages already used by most people?

那么,我会是微软吗,当大多数人已经使用的更多社区活跃语言已经提供了相同的功能时,为什么我要实现很少有人会使用的功能?

Conclusion?

结论?

C++0x will be included, as extention of VS 2008, or on the next generation (generations?) of Visual Studio.

C++0x 将被包括在内,作为 VS 2008 的扩展,或在 Visual Studio 的下一代(几代?)。

The C99 features not already implemented won't be in the next years, unless something dramatic happens (a country full of C99 developers appears out of nowhere?)

尚未实现的 C99 功能将不会在未来几年内出现,除非发生重大事件(一个充满 C99 开发人员的国家突然出现?)

Edit 2011-04-14

编辑 2011-04-14

Apparently, the "country full of C99 developers" already exist: http://blogs.msdn.com/vcblog/archive/2007/11/05/iso-c-standard-update.aspx#6415401
^_^

显然,“充满 C99 开发者的国家”已经存在:http: //blogs.msdn.com/vcblog/archive/2007/11/05/iso-c-standard-update.aspx#6415401
^_^

Still, the last comment at: http://blogs.msdn.com/vcblog/archive/2007/11/05/iso-c-standard-update.aspx#6828778is clear enough, I guess.

尽管如此,我想,http: //blogs.msdn.com/vcblog/archive/2007/11/05/iso-c-standard-update.aspx#6828778 上的最后一条评论已经足够清楚了。

Edit 2012-05-03

编辑 2012-05-03

Herb Sutter made it clear that:

Herb Sutter 明确表示:

  1. Our primary goal is to support "most of C99/C11 that is a subset of ISO C++98/C++11."
  2. We also for historical reasons ship a C90 compiler which accepts (only) C90 and not C++
  3. We do not plan to support ISO C features that are not part of either C90 or ISO C++.
  1. 我们的主要目标是支持“作为 ISO C++98/C++11 子集的大部分 C99/C11”。
  2. 我们还出于历史原因发布了一个 C90 编译器,它接受(仅)C90 而不是 C++
  3. 我们不打算支持不属于 C90 或 ISO C++ 的 ISO C 功能。

The blog post add links and further explanations for those decisions.

博客文章为这些决定添加了链接和进一步解释。

Source: http://herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/

资料来源:http: //herbsutter.com/2012/05/03/reader-qa-what-about-vc-and-c99/

回答by vulcan raven

Starting from VC2013 preview 1, C99, a more diversified set of C++11 and some newly introduced C++14 standards are supported. Checkout the official blog for more details: http://blogs.msdn.com/b/vcblog/archive/2013/06/27/what-s-new-for-visual-c-developers-in-vs2013-preview.aspx

VC2013 预览版 1、C99 开始,支持更加多样化的 C++11 集和一些新引入的 C++14 标准。查看官方博客了解更多详情:http: //blogs.msdn.com/b/vcblog/archive/2013/06/27/what-s-new-for-visual-c-developers-in-vs2013-preview。 aspx

Update:

更新:

From https://news.ycombinator.com/item?id=9434483(Stephan T Lavavej aka: STL is maintainer of STL @VC team):

来自https://news.ycombinator.com/item?id=9434483(StephanT Lavavej 又名:STL 是 STL @VC 团队的维护者):

Specifically, in 2015 our C99 Standard Library implementation is complete, except for tgmath.h (irrelevant in C++) and the CX_LIMITED_RANGE/FP_CONTRACT pragma macros.

具体来说,在 2015 年,我们的 C99 标准库实现已经完成,除了 tgmath.h(与 C++ 无关)和 CX_LIMITED_RANGE/FP_CONTRACT 编译指示宏。

Check this post out for details: http://blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17-features-in-vs-2015-rc.aspx.

查看此帖子了解详细信息:http: //blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17-features-in-vs-2015-rc.aspx

回答by MSalters

I've been involved in the ISO C++ work (2000-2005), and Microsoft made significant contributions to that language. There's no doubt they will work on C++0x, but they'll need a bit more time than say Intel. Micosoft has to deal with a larger codebase that often uses their proprietary extensions. This simply makes for a longer testfase. Yet, they will support most of C++0x eventually (export still isn't loved though, or so I understand).

我参与了 ISO C++ 工作(2000-2005),Microsoft 为该语言做出了重大贡献。毫无疑问,他们将在 C++0x 上工作,但他们需要比英特尔多一点的时间。Micosoft 必须处理经常使用其专有扩展的更大的代码库。这只会导致更长的测试用例。然而,它们最终将支持大部分 C++0x(尽管仍然不喜欢导出,或者我理解)。

When it comes to ISO C, the people working on standard are not representative for Microsofts market. Microsofts customers can use C++98 if they're just looking for a better C. So why would Microsoft spend money on C99? Sure, Microsoft cherry-picked parts, but that's sane business. They'd need those for C++0x anyway, so why wait?

说到 ISO C,从事标准工作的人并不代表微软的市场。微软的客户如果只是在寻找更好的 C 就可以使用 C++98。那么微软为什么要在 C99 上花钱呢?当然,微软精心挑选了零件,但这是正常的业务。无论如何,他们需要 C++0x 的那些,所以为什么要等待?

回答by Dark Shikari

MSVC support for C is unfortunately very lacking. It only supports the portion of C99 that is a subset of C++... which means that, for example, it is physically impossible to compile ffmpeg or its libav* libraries in MSVC, because they use many C99 features such as named struct elements. This is made worse by the fact that libavcodec also requires a compiler that maintains stack alignment, which MSVC doesn't.

不幸的是,MSVC 对 C 的支持非常缺乏。它只支持 C99 中作为 C++ 子集的部分……这意味着,例如,在 MSVC 中编译 ffmpeg 或其 libav* 库在物理上是不可能的,因为它们使用了许多 C99 功能,例如命名结构元素。由于 libavcodec 还需要一个保持堆栈对齐的编译器,而 MSVC 没有,这使情况变得更糟。

I work on x264, which unlike ffmpeg doesmake an effort to support MSVC, though doing so has often been a nightmare in and of itself. It doesn't maintain stack alignment even if you explicitly pass the highest function call through an explicit assembly-based stack alignment function, so all functions that require an aligned stack have to be disabled. Its also been very annoying that I cannot use vararrays either; perhaps this is for the best, since apparently GCC massively pessimizes them performance-wise.

我在 x264 上工作,与 ffmpeg 不同,它确实努力支持 MSVC,尽管这样做本身常常是一场噩梦。即使您通过基于程序集的显式堆栈对齐函数显式传递最高函数调用,它也不会保持堆栈对齐,因此必须禁用所有需要对齐堆栈的函数。我也不能使用可变数组也很烦人;也许这是最好的,因为显然 GCC 在性能方面极大地悲观了它们。

回答by fbrereto

A more recent post about MSVC's C++11 feature compatibility for MSVC 2010 and 2011 is now online.

一篇关于 MSVC 的 C++11 特性对 MSVC 2010 和 2011 的兼容性的最新帖子现已上线

回答by Michael Burr

Updated information on this:

关于此的更新信息:

There is now (10 Nov 2008) a "Community Tech Preview" (CTP) of VS2010 which contains a preview of VC10 that has someparts of C++0x implemented (note that VC10 will not have the full set of C++0x changes implemented even when VC10 is released):

现在(2008 年 11 月 10 日)有一个 VS2010 的“社区技术预览”(CTP),其中包含 VC10 的预览,其中实现了 C++0x 的某些部分(请注意,VC10 将没有完整的 C++0x即使发布 VC10 也会实施更改):

http://www.microsoft.com/downloads/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814&displaylang=en

http://www.microsoft.com/downloads/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814&displaylang=en

Some details on what's new in the VC10 CTP:

有关 VC10 CTP 新功能的一些详细信息:

As noted in the above article, "The Visual C++ compiler in the Microsoft Visual Studio 2010 September Community Technology Preview (CTP) contains support for four C++0x language features, namely:"

如上述文章所述,“Microsoft Visual Studio 2010 九月社区技术预览版 (CTP) 中的 Visual C++ 编译器包含对四种 C++0x 语言功能的支持,即:”

  • lambdas,
  • auto,
  • static_assert,
  • rvalue references
  • 拉姆达,
  • 汽车,
  • 静态断言,
  • 右值引用

回答by JesperE

Microsoft has never expressed any real interest in keeping up-to-speed with the c99-standard (which is getting old by now). Sad for C-programmers, but I suspect that Microsoft cares more for the C++-community.

Microsoft 从未表示过任何真正的兴趣跟上 c99 标准(现在已经过时)。为 C 程序员感到难过,但我怀疑微软更关心 C++ 社区。

回答by OregonGhost

Visual C++ 2008 SP1 contains parts of TR1 at least, and from time to time, the Visual C++ team is blogging or talking about C++0x, so I guess they will support it at some time in the feature. I didn't read anything official though.

Visual C++ 2008 SP1 至少包含 TR1 的部分内容,并且 Visual C++ 团队不时在博客上或谈论 C++0x,所以我猜他们会在某个时间在功能中支持它。虽然我没有阅读任何官方内容。

回答by QBziZ

Herb Sutter is the chairman of the ISO C++ standards body and also works for Microsoft. I don't know about the Visual Studio C standard - mainly because I never use plain C - but Microsoft is sure trying to push the new C++ standard forward. Evidence of this is - like OregonGhost mentioned - the TR1 that is included in the latest Visual Studio Service Release.

Herb Sutter 是 ISO C++ 标准组织的主席,同时也为 Microsoft 工作。我不了解 Visual Studio C 标准 - 主要是因为我从不使用普通 C - 但微软肯定会努力推动新的 C++ 标准向前发展。这方面的证据 - 就像提到的 OregonGhost - 包含在最新 Visual Studio 服务版本中的 TR1。