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

How can I get the default mode for c++ of g++ compiler without referring the doc?

本文关键字:g++ 编译器 c++ 模式 默认 情况下 参考 参考文 文档      更新时间:2023-10-16

我想知道当前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)

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

您可以随时使用 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.

如果要在命令行中获取它(没有寻呼机),则可以使用-Pman指定寻呼机:

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

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

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