如何在不参考doc的情况下获得g ++编译器的c ++默认模式?

时间:2017-01-03 09:12:54

标签: c++ gcc g++

我想知道当前c++编译器的g++的默认模式。除了引用文档,例如this

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)

但不幸的是,这并没有提供这方面的知识。

2 个答案:

答案 0 :(得分: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.

如果您想在命令行中获取它(没有寻呼机),那么您可以使用man指定-P的寻呼机:

$ 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.

答案 1 :(得分:2)

不,您只能从您的版本的手册/文档中发现它。

当然,如果您需要此信息,您可能有兴趣针对特定标准进行编译,在这种情况下,您无论如何都要在构建时指定自己的-std值, ? :)