📄 c---dialect-options.html
字号:
<html lang="en">
<head>
<title>Using the GNU Compiler Collection (GCC)</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using the GNU Compiler Collection (GCC)">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
<!--
Copyright © 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
<p>Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License" and "Funding
Free Software", the Front-Cover texts being (a) (see below), and with
the Back-Cover Texts being (b) (see below). A copy of the license is
included in the section entitled "GNU Free Documentation License".
<p>(a) The FSF's Front-Cover Text is:
<p>A GNU Manual
<p>(b) The FSF's Back-Cover Text is:
<p>You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development.-->
</head>
<body>
<div class="node">
<p>
Node:<a name="C++%20Dialect%20Options">C++ Dialect Options</a>,
Next:<a rel="next" accesskey="n" href="Objective-C-Dialect-Options.html#Objective-C%20Dialect%20Options">Objective-C Dialect Options</a>,
Previous:<a rel="previous" accesskey="p" href="C-Dialect-Options.html#C%20Dialect%20Options">C Dialect Options</a>,
Up:<a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking%20GCC">Invoking GCC</a>
<hr><br>
</div>
<h3 class="section">Options Controlling C++ Dialect</h3>
<p>This section describes the command-line options that are only meaningful
for C++ programs; but you can also use most of the GNU compiler options
regardless of what language your program is in. For example, you
might compile a file <code>firstClass.C</code> like this:
<pre class="example"> g++ -g -frepo -O -c firstClass.C
</pre>
<p>In this example, only <code>-frepo</code> is an option meant
only for C++ programs; you can use the other options with any
language supported by GCC.
<p>Here is a list of options that are <em>only</em> for compiling C++ programs:
<dl>
<br><dt><code>-fabi-version=</code><var>n</var><code></code>
<dd>Use version <var>n</var> of the C++ ABI. Version 1 is the version of the C++
ABI that first appeared in G++ 3.2. Version 0 will always be the
version that conforms most closely to the C++ ABI specification.
Therefore, the ABI obtained using version 0 will change as ABI bugs are
fixed.
<p>The default is version 1.
<br><dt><code>-fno-access-control</code>
<dd>Turn off all access checking. This switch is mainly useful for working
around bugs in the access control code.
<br><dt><code>-fcheck-new</code>
<dd>Check that the pointer returned by <code>operator new</code> is non-null
before attempting to modify the storage allocated. This check is
normally unnecessary because the C++ standard specifies that
<code>operator new</code> will only return <code>0</code> if it is declared
<code>throw()</code>, in which case the compiler will always check the
return value even without this option. In all other cases, when
<code>operator new</code> has a non-empty exception specification, memory
exhaustion is signalled by throwing <code>std::bad_alloc</code>. See also
<code>new (nothrow)</code>.
<br><dt><code>-fconserve-space</code>
<dd>Put uninitialized or runtime-initialized global variables into the
common segment, as C does. This saves space in the executable at the
cost of not diagnosing duplicate definitions. If you compile with this
flag and your program mysteriously crashes after <code>main()</code> has
completed, you may have an object that is being destroyed twice because
two definitions were merged.
<p>This option is no longer useful on most targets, now that support has
been added for putting variables into BSS without making them common.
<br><dt><code>-fno-const-strings</code>
<dd>Give string constants type <code>char *</code> instead of type <code>const
char *</code>. By default, G++ uses type <code>const char *</code> as required by
the standard. Even if you use <code>-fno-const-strings</code>, you cannot
actually modify the value of a string constant, unless you also use
<code>-fwritable-strings</code>.
<p>This option might be removed in a future release of G++. For maximum
portability, you should structure your code so that it works with
string constants that have type <code>const char *</code>.
<br><dt><code>-fdollars-in-identifiers</code>
<dd>Accept <code>$</code> in identifiers. You can also explicitly prohibit use of
<code>$</code> with the option <code>-fno-dollars-in-identifiers</code>. (GNU C allows
<code>$</code> by default on most target systems, but there are a few exceptions.)
Traditional C allowed the character <code>$</code> to form part of
identifiers. However, ISO C and C++ forbid <code>$</code> in identifiers.
<br><dt><code>-fno-elide-constructors</code>
<dd>The C++ standard allows an implementation to omit creating a temporary
which is only used to initialize another object of the same type.
Specifying this option disables that optimization, and forces G++ to
call the copy constructor in all cases.
<br><dt><code>-fno-enforce-eh-specs</code>
<dd>Don't check for violation of exception specifications at runtime. This
option violates the C++ standard, but may be useful for reducing code
size in production builds, much like defining <code>NDEBUG</code>. The compiler
will still optimize based on the exception specifications.
<br><dt><code>-fexternal-templates</code>
<dd>
<p>Cause <code>#pragma interface</code> and <code>implementation</code> to apply to
template instantiation; template instances are emitted or not according
to the location of the template definition. See <a href="Template-Instantiation.html#Template%20Instantiation">Template Instantiation</a>, for more information.
<p>This option is deprecated.
<br><dt><code>-falt-external-templates</code>
<dd>Similar to <code>-fexternal-templates</code>, but template instances are
emitted or not according to the place where they are first instantiated.
See <a href="Template-Instantiation.html#Template%20Instantiation">Template Instantiation</a>, for more information.
<p>This option is deprecated.
<br><dt><code>-ffor-scope</code>
<dd><dt><code>-fno-for-scope</code>
<dd>If <code>-ffor-scope</code> is specified, the scope of variables declared in
a <i>for-init-statement</i> is limited to the <code>for</code> loop itself,
as specified by the C++ standard.
If <code>-fno-for-scope</code> is specified, the scope of variables declared in
a <i>for-init-statement</i> extends to the end of the enclosing scope,
as was the case in old versions of G++, and other (traditional)
implementations of C++.
<p>The default if neither flag is given to follow the standard,
but to allow and give a warning for old-style code that would
otherwise be invalid, or have different behavior.
<br><dt><code>-fno-gnu-keywords</code>
<dd>Do not recognize <code>typeof</code> as a keyword, so that code can use this
word as an identifier. You can use the keyword <code>__typeof__</code> instead.
<code>-ansi</code> implies <code>-fno-gnu-keywords</code>.
<br><dt><code>-fno-implicit-templates</code>
<dd>Never emit code for non-inline templates which are instantiated
implicitly (i.e. by use); only emit code for explicit instantiations.
See <a href="Template-Instantiation.html#Template%20Instantiation">Template Instantiation</a>, for more information.
<br><dt><code>-fno-implicit-inline-templates</code>
<dd>Don't emit code for implicit instantiations of inline templates, either.
The default is to handle inlines differently so that compiles with and
without optimization will need the same set of explicit instantiations.
<br><dt><code>-fno-implement-inlines</code>
<dd>To save space, do not emit out-of-line copies of inline functions
controlled by <code>#pragma implementation</code>. This will cause linker
errors if these functions are not inlined everywhere they are called.
<br><dt><code>-fms-extensions</code>
<dd>Disable pedantic warnings about constructs used in MFC, such as implicit
int and getting a pointer to member function via non-standard syntax.
<br><dt><code>-fno-nonansi-builtins</code>
<dd>Disable built-in declarations of functions that are not mandated by
ANSI/ISO C. These include <code>ffs</code>, <code>alloca</code>, <code>_exit</code>,
<code>index</code>, <code>bzero</code>, <code>conjf</code>, and other related functions.
<br><dt><code>-fno-operator-names</code>
<dd>Do not treat the operator name keywords <code>and</code>, <code>bitand</code>,
<code>bitor</code>, <code>compl</code>, <code>not</code>, <code>or</code> and <code>xor</code> as
synonyms as keywords.
<br><dt><code>-fno-optional-diags</code>
<dd>Disable diagnostics that the standard says a compiler does not need to
issue. Currently, the only such diagnostic issued by G++ is the one for
a name having multiple meanings within a class.
<br><dt><code>-fpermissive</code>
<dd>Downgrade messages about nonconformant code from errors to warnings. By
default, G++ effectively sets <code>-pedantic-errors</code> without
<code>-pedantic</code>; this option reverses that. This behavior and this
option are superseded by <code>-pedantic</code>, which works as it does for GNU C.
<br><dt><code>-frepo</code>
<dd>Enable automatic template instantiation at link time. This option also
implies <code>-fno-implicit-templates</code>. See <a href="Template-Instantiation.html#Template%20Instantiation">Template Instantiation</a>, for more information.
<br><dt><code>-fno-rtti</code>
<dd>Disable generation of information about every class with virtual
functions for use by the C++ runtime type identification features
(<code>dynamic_cast</code> and <code>typeid</code>). If you don't use those parts
of the language, you can save some space by using this flag. Note that
exception handling uses the same information, but it will generate it as
needed.
<br><dt><code>-fstats</code>
<dd>Emit statistics about front-end processing at the end of the compilation.
This information is generally only useful to the G++ development team.
<br><dt><code>-ftemplate-depth-</code><var>n</var><code></code>
<dd>Set the maximum instantiation depth for template classes to <var>n</var>.
A limit on the template instantiation depth is needed to detect
endless recursions during template class instantiation. ANSI/ISO C++
conforming programs must not rely on a maximum depth greater than 17.
<br><dt><code>-fuse-cxa-atexit</code>
<dd>Register destructors for objects with static storage duration with the
<code>__cxa_atexit</code> function rather than the <code>atexit</code> function.
This option is required for fully standards-compliant handling of static
destructors, but will only work if your C library supports
<code>__cxa_atexit</code>.
<br><dt><code>-fvtable-gc</code>
<dd>Emit special relocations for vtables and virtual function references
so that the linker can identify unused virtual functions and zero out
vtable slots that refer to them. This is most useful with
<code>-ffunction-sections</code> and <code>-Wl,--gc-sections</code>, in order to
also discard the functions themselves.
<p>This optimization requires GNU as and GNU ld. Not all systems support
this option. <code>-Wl,--gc-sections</code> is ignored without <code>-static</code>.
<br><dt><code>-fno-weak</code>
<dd>Do not use weak symbol support, even if it is provided by the linker.
By default, G++ will use weak symbols if they are available. This
option exists only for testing, and should not be used by end-users;
it will result in inferior code and has no benefits. This option may
be removed in a future release of G++.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -