简体   繁体   English

当默认标准为 201402L (c++14) 时,g++ 是否与 g++ -std=c++14 不同?

[英]Is g++ different than g++ -std=c++14 when the default standard is 201402L (c++14)?

I was trying to make use of precompiled headers to speed up compilation following this link: https://codeforces.com/blog/entry/53909我试图利用预编译的头文件来加快以下链接的编译速度: https://codeforces.com/blog/entry/53909

I observed that pre-compilation of headers and subsequent compilation of.cpp programs have to be done using the same g++ flags for the speed-up to work, which makes sense.我观察到头文件的预编译和.cpp 程序的后续编译必须使用相同的 g++ 标志来完成,以加快工作速度,这是有道理的。 However, explicitly setting the c++ standard to the default one did not work.但是,将 c++ 标准显式设置为默认值不起作用。 So, neither of pre-compilation using g++ stdc++.h and subsequent g++ -std=c++14 program.cpp , nor, g++ -std=c++14 and g++ program.cpp worked. So, neither of pre-compilation using g++ stdc++.h and subsequent g++ -std=c++14 program.cpp , nor, g++ -std=c++14 and g++ program.cpp worked.

This didn't make sense to me as I knew that my compiler, x86_64-w64-mingw32-g++.exe (gcc version 10.2.0), by default, conforms to 201402L (c++14) standard, which I figured using g++ -dM -E -x c++ /dev/null | fgrep __cplusplus这对我来说没有意义,因为我知道我的编译器 x86_64-w64-mingw32-g++.exe(gcc 版本 10.2.0)默认符合 201402L(c++14)标准,我想使用g++ -dM -E -x c++ /dev/null | fgrep __cplusplus g++ -dM -E -x c++ /dev/null | fgrep __cplusplus , and getting the following response: g++ -dM -E -x c++ /dev/null | fgrep __cplusplus ,并得到以下响应:

#define __cplusplus 201402L

So, my question is, what is the difference between g++ and g++ -std=c++14 when g++, by default, adheres to 201402L?所以,我的问题是,g++ 和 g++ -std=c++14 之间有什么区别,默认情况下,遵守 L2? Also, is it significant enough for me to specifically opt for either one of them?另外,对我来说,专门选择其中任何一个是否足够重要?

GCC doesn't compile with -std=c++14 by default. GCC 默认不使用-std=c++14编译。 The description of the -std flag from the GCC man pages (for version 9.3.0) says GCC 手册页(对于版本 9.3.0)中-std标志的描述说

-std= Determine the language standard. -std=确定语言标准。 This option is currently only supported when compiling C or C++.当前仅在编译 C 或 C++ 时支持此选项。

The compiler can accept several base standards, such as c90 or c++98, and GNU dialects of those standards, such as gnu90 or gnu++98.编译器可以接受几个基本标准,例如 c90 或 c++98,以及这些标准的 GNU 方言,例如 gnu90 或 gnu++98。 When a base standard is specified, the compiler accepts all programs following that standard plus those using GNU extensions that do not contradict it.当一个基本标准被指定时,编译器接受所有遵循该标准的程序,以及那些使用与它不矛盾的 GNU 扩展的程序。
. . . . . .
A value for this option must be provided;必须提供此选项的值; possible values are可能的值为
. . . . . .
c++14 c++14
c++1y c++1y
The 2014 ISO C++ standard plus amendments. 2014 ISO C++ 标准加上修正案。 The name c++1y is deprecated.名称 c++1y 已弃用。

gnu++14 gnu++14
gnu++1y gnu++1y
GNU dialect of -std=c++14. -std=c++14 的 GNU 方言。 This is the default for C++ code.这是 C++ 代码的默认值。 The name gnu++1y is deprecated.名称 gnu++1y 已弃用。
. . . . . .

Emphasis mine.强调我的。 The current default is -std=gnu++14 , which targets the C++14 standard while also enabling GNU extensions to the C++ language.当前默认值为-std=gnu++14 ,它以 C++14 标准为目标,同时还启用了对 C++ 语言的GNU 扩展 The distinction between the -std=c++XX flags and the -std=gnu++XX flags is explained further in What are the differences between -std=c++11 and -std=gnu++11? -std=c++XX标志和-std=gnu++XX标志之间的区别在 -std=c++11 和 -std=gnu++11 之间有什么区别? . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM