如何在不查阅文档的情况下获取g++编译器的C++默认模式?

4

我想知道当前 g++ 编译器的 c++ 默认模式。除了参考文档,例如 这个

The default mode for C++ is now -std=gnu++14 instead of -std=gnu++98.

我可以从g++命令行获取此模式吗? 我试图从g++ -v中查找此信息:

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/6.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 6.2.1 20160830 (GCC)

但很遗憾,这并没有提供这个知识。

3
您可以从 echo __cplusplus|g++ -x c++ -P -E - 推断出来。 - Marc Glisse
2个回答

2
不,你只能从你版本的手册/文档中发现它。
当然,如果您需要这些信息,您可能有兴趣针对特定标准进行编译,在这种情况下,您在构建时会指定自己的-std值,对吧? :)

2

您可以随时使用man,例如:(请注意默认是gnu++14

man g++

...
       -std=
           Determine the language standard.   This option is currently only supported when compiling C or 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.  When a base standard is specified, the compiler accepts all programs following that standard plus those using GNU
           extensions that do not contradict it.  For example, -std=c90 turns off certain features of GCC that are incompatible with ISO C90, such as the "asm" and "typeof" keywords, but not other GNU extensions that do not have a meaning in ISO C90, such as
           omitting the middle term of a "?:" expression. On the other hand, when a GNU dialect of a standard is specified, all features supported by the compiler are enabled, even when those features change the meaning of the base standard.  As a result, some
           strict-conforming programs may be rejected.  The particular standard is used by -Wpedantic to identify which features are GNU extensions given that version of the standard. For example -std=gnu90 -Wpedantic warns about C++ style // comments, while
           -std=gnu99 -Wpedantic does not.

           A value for this option must be provided; possible values are

...

           c++14
           c++1y
               The 2014 ISO C++ standard plus amendments.  The name c++1y is deprecated.

           gnu++14
           gnu++1y
               GNU dialect of -std=c++14.  This is the default for C++ code.  The name gnu++1y is deprecated.

如果您想在命令行中获取它(不使用分页器),则可以使用-P指定man的分页器:

$ man -P cat g++ | grep "^[[:space:]]*\-std=[^s]" -A100 | grep -B2 "default.*C++"
           gnu++14
           gnu++1y
               GNU dialect of -std=c++14.  This is the default for C++ code.  The name gnu++1y is deprecated.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接