-std=c++11 和 -std=gnu++11 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10613126/
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 14:16:51  来源:igfitidea点击:

What are the differences between -std=c++11 and -std=gnu++11?

c++gccc++11clang

提问by Klaim

What are the differences between -std=c++11and -std=gnu++11as compilation parameter for gcc and clang? Same question with c99and gnu99? I know about C++ and C standards, it's the differences in the parameters that interest me.

gcc和clang的编译参数-std=c++11-std=gnu++11作为编译参数有什么区别?与c99和相同的问题gnu99?我了解 C++ 和 C 标准,我感兴趣的是参数的差异。

I've read somewhere that it has to do with some extensions but it is not clear to me which ones and how to choose between one or the other for a new project.

我在某处读到它与一些扩展有关,但我不清楚哪些扩展以及如何在一个或另一个之间进行选择以用于新项目。

采纳答案by daramarak

As you have found out yourself, the difference between the two options is whether GNU extensions that violates/extend the C++ standard are enabled or not. The GNU C++ extensions are described here. You can also use most of the GNU C extensions (described here) in your C++ programs. It would be also useful to read about the -WpedanticGCC option here.

正如您自己发现的那样,这两个选项之间的区别在于是否启用了违反/扩展 C++ 标准的 GNU 扩展。此处描述GNU C++ 扩展。您还可以在 C++ 程序中使用大多数 GNU C 扩展(在此处描述)。在此处阅读有关-WpedanticGCC 选项的信息也很有用。

Note that some extensions can still be in effect when using -std=c++11, as long as they do not contradict the standard. For instance, when using the MinGW compiler, I need the extensions for a working Boost.Lexical_Cast. But, as long as you don't use any of them, you are better off sticking to the standard without extensions for maximum portability. This might come in handy if you find yourself forced to change compiler.

请注意,某些扩展在使用时仍然有效-std=c++11,只要它们不与标准相矛盾。例如,当使用 MinGW 编译器时,我需要工作Boost.Lexical_Cast. 但是,只要您不使用它们中的任何一个,您最好坚持标准而不使用扩展以获得最大的可移植性。如果您发现自己被迫更改编译器,这可能会派上用场。