⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 invoke.texi

📁 GCC编译器源代码
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
cache.Because access privileges (visibility) to members and member functionsmay differ from one function context to the next, G++ may need to flushthe cache.  With the @samp{-fmemoize-lookups} flag, the cache is flushedafter every function that is compiled.  The @samp{-fsave-memoized} flagenables the same software cache, but when the compiler determines thatthe context of the last function compiled would yield the same accessprivileges of the next function to compile, it preserves the cache.This is most helpful when defining many member functions for the sameclass: with the exception of member functions which are friends of otherclasses, each member function has exactly the same access privileges asevery other, and the cache need not be flushed.The code that implements these flags has rotted; you should probablyavoid using them.@item -fstrict-prototypeWithin an @samp{extern "C"} linkage specification, treat a functiondeclaration with no arguments, such as @samp{int foo ();}, as declaringthe function to take no arguments.  Normally, such a declaration meansthat the function @code{foo} can take any combination of arguments, asin C.  @samp{-pedantic} implies @samp{-fstrict-prototype} unlessoverridden with @samp{-fno-strict-prototype}.This flag no longer affects declarations with C++ linkage.@item -fname-mangling-version-@var{n}Control the way in which names are mangled.  Version 0 is compatiblewith versions of g++ before 2.8.  Version 1 is the default.  Version 1will allow correct mangling of function templates.  For example, version 0 mangling does not mangle foo<int, double> and foo<int, char>given this declaration:@exampletemplate <class T, class U> void foo(T t);@end example@item -fno-nonnull-objectsDon't assume that a reference is initialized to refer to a valid object.Although the current C++ Working Paper prohibits null references, someold code may rely on them, and you can use @samp{-fno-nonnull-objects}to turn on checking.At the moment, the compiler only does this checking for conversions tovirtual base classes.@item -foperator-namesRecognize the operator name keywords @code{and}, @code{bitand},@code{bitor}, @code{compl}, @code{not}, @code{or} and @code{xor} assynonyms for the symbols they refer to.  @samp{-ansi} implies@samp{-foperator-names}.@item -fthis-is-variablePermit assignment to @code{this}.  The incorporation of user-definedfree store management into C++ has made assignment to @samp{this} ananachronism.  Therefore, by default it is invalid to assign to@code{this} within a class member function; that is, GNU C++ treats@samp{this} in a member function of class @code{X} as a non-lvalue oftype @samp{X *}.  However, for backwards compatibility, you can make itvalid with @samp{-fthis-is-variable}.@item -fvtable-thunksUse @samp{thunks} to implement the virtual function dispatch table(@samp{vtable}).  The traditional (cfront-style) approach toimplementing vtables was to store a pointer to the function and twooffsets for adjusting the @samp{this} pointer at the call site.  Newerimplementations store a single pointer to a @samp{thunk} function whichdoes any necessary adjustment and then calls the target function.This option also enables a heuristic for controlling emission ofvtables; if a class has any non-inline virtual functions, the vtablewill be emitted in the translation unit containing the first one ofthose.@item -ftemplate-depth-@var{n}Set the maximum instantiation depth for template classes to @var{n}.A limit on the template instantiation depth is needed to detectendless recursions during template class instantiation. ANSI/ISO C++conforming programs must not rely on a maximum depth greater than 17.@item -nostdinc++Do not search for header files in the standard directories specific toC++, but do still search the other standard directories.  (This optionis used when building libg++.)@item -traditionalFor C++ programs (in addition to the effects that apply to both C andC++), this has the same effect as @samp{-fthis-is-variable}.@xref{C Dialect Options,, Options Controlling C Dialect}.@end tableIn addition, these optimization, warning, and code generation optionshave meanings only for C++ programs:@table @code@item -fno-default-inlineDo not assume @samp{inline} for functions defined inside a class scope.@xref{Optimize Options,,Options That Control Optimization}.@item -Wold-style-cast@itemx -Woverloaded-virtual@itemx -Wtemplate-debuggingWarnings that apply only to C++ programs.  @xref{WarningOptions,,Options to Request or Suppress Warnings}.@item -Weffc++Warn about violation of some style rules from Effective C++ by Scott Myers.@item +e@var{n}Control how virtual function definitions are used, in a fashioncompatible with @code{cfront} 1.x.  @xref{Code Gen Options,,Options forCode Generation Conventions}.@end table@node Warning Options@section Options to Request or Suppress Warnings@cindex options to control warnings@cindex warning messages@cindex messages, warning@cindex suppressing warningsWarnings are diagnostic messages that report constructions whichare not inherently erroneous but which are risky or suggest theremay have been an error.You can request many specific warnings with options beginning @samp{-W},for example @samp{-Wimplicit} to request warnings on implicitdeclarations.  Each of these specific warning options also has anegative form beginning @samp{-Wno-} to turn off warnings;for example, @samp{-Wno-implicit}.  This manual lists only one of thetwo forms, whichever is not the default.These options control the amount and kinds of warnings produced by GNUCC:@table @code@cindex syntax checking@item -fsyntax-onlyCheck the code for syntax errors, but don't do anything beyond that.@item -pedanticIssue all the warnings demanded by strict ANSI standard C; rejectall programs that use forbidden extensions.Valid ANSI standard C programs should compile properly with or withoutthis option (though a rare few will require @samp{-ansi}).  However,without this option, certain GNU extensions and traditional C featuresare supported as well.  With this option, they are rejected.@samp{-pedantic} does not cause warning messages for use of thealternate keywords whose names begin and end with @samp{__}.  Pedanticwarnings are also disabled in the expression that follows@code{__extension__}.  However, only system header files should usethese escape routes; application programs should avoid them.@xref{Alternate Keywords}.This option is not intended to be @i{useful}; it exists only to satisfypedants who would otherwise claim that GNU CC fails to support the ANSIstandard.Some users try to use @samp{-pedantic} to check programs for strict ANSIC conformance.  They soon find that it does not do quite what they want:it finds some non-ANSI practices, but not all---only those for whichANSI C @emph{requires} a diagnostic.A feature to report any failure to conform to ANSI C might be useful insome instances, but would require considerable additional work and wouldbe quite different from @samp{-pedantic}.  We recommend, rather, thatusers take advantage of the extensions of GNU C and disregard thelimitations of other compilers.  Aside from certain supercomputers andobsolete small machines, there is less and less reason ever to use anyother C compiler other than for bootstrapping GNU CC.@item -pedantic-errorsLike @samp{-pedantic}, except that errors are produced rather thanwarnings.@item -wInhibit all warning messages.@item -Wno-importInhibit warning messages about the use of @samp{#import}.@item -Wchar-subscriptsWarn if an array subscript has type @code{char}.  This is a common causeof error, as programmers often forget that this type is signed on somemachines.@item -WcommentWarn whenever a comment-start sequence @samp{/*} appears in a @samp{/*}comment, or whenever a Backslash-Newline appears in a @samp{//} comment.@item -WformatCheck calls to @code{printf} and @code{scanf}, etc., to make sure thatthe arguments supplied have types appropriate to the format stringspecified.@item -Wimplicit-intWarn when a declaration does not specify a type.@item -Wimplicit-function-declarationsWarn whenever a function is used before being declared.@item -WimplicitSame as @samp{-Wimplicit-int} @samp{-Wimplicit-function-declaration}.@item -WmainWarn if the type of @samp{main} is suspicious.  @samp{main} should be afunction with external linkage, returning int, taking either zeroarguments, two, or three arguments of appropriate types.  @item -WparenthesesWarn if parentheses are omitted in certain contexts, suchas when there is an assignment in a context where a truth valueis expected, or when operators are nested whose precedence peopleoften get confused about.Also warn about constructions where there may be confusion to which@code{if} statement an @code{else} branch belongs.  Here is an example ofsuch a case:@smallexample@{  if (a)    if (b)      foo ();  else    bar ();@}@end smallexampleIn C, every @code{else} branch belongs to the innermost possible @code{if}statement, which in this example is @code{if (b)}.  This is often notwhat the programmer expected, as illustrated in the above example byindentation the programmer chose.  When there is the potential for thisconfusion, GNU C will issue a warning when this flag is specified.To eliminate the warning, add explicit braces around the innermost@code{if} statement so there is no way the @code{else} could belong tothe enclosing @code{if}.  The resulting code would look like this:@smallexample@{  if (a)    @{      if (b)        foo ();      else        bar ();    @}@}@end smallexample@item -Wreturn-typeWarn whenever a function is defined with a return-type that defaultsto @code{int}.  Also warn about any @code{return} statement with noreturn-value in a function whose return-type is not @code{void}.@item -WswitchWarn whenever a @code{switch} statement has an index of enumeral typeand lacks a @code{case} for one or more of the named codes of thatenumeration.  (The presence of a @code{default} label prevents thiswarning.)  @code{case} labels outside the enumeration range alsoprovoke warnings when this option is used.@item -WtrigraphsWarn if any trigraphs are encountered (assuming they are enabled).@item -WunusedWarn whenever a variable is unused aside from its declaration,whenever a function is declared static but never defined, whenever alabel is declared but not used, and whenever a statement computes aresult that is explicitly not used.In order to get a warning about an unused function parameter, you mustspecify both @samp{-W} and @samp{-Wunused}.To suppress this warning for an expression, simply cast it to void.  Forunused variables and parameters, use the @samp{unused} attribute(@pxref{Variable Attributes}).@item -WuninitializedAn automatic variable is used without first being initialized.These warnings are possible only in optimizing compilation,because they require data flow information that is computed onlywhen optimizing.  If you don't specify @samp{-O}, you simply won'tget these warnings.These warnings occur only for variables that are candidates forregister allocation.  Therefore, they do not occur for a variable thatis declared @code{volatile}, or whose address is taken, or whose sizeis other than 1, 2, 4 or 8 bytes.  Also, they do not occur forstructures, unions or arrays, even when they are in registers.Note that there may be no warning about a variable that is used onlyto compute a value that itself is never used, because suchcomputations may be deleted by data flow analysis before the warningsare printed.These warnings are made optional because GNU CC is not smartenough to see all the reasons why the code might be correctdespite appearing to have an error.  Here is one example of howthis can happen:@smallexample@{  int x;  switch (y)    @{    case 1: x = 1;      break;    case 2: x = 4;      break;    case 3: x = 5;    @}  foo (x);@}@end smallexample@noindentIf the value of @code{y} is always 1, 2 or 3, then @code{x} isalways initialized, but GNU CC doesn't know this.  Here isanother common case:@smallexample@{  int save_y;  if (change_y) save_y = y, y = new_y;  @dots{}  if (change_y) y = save_y;@}@end smallexample@noindentThis has no bug because @code{save_y} is used only if it is set.Some spurious warnings can be avoided if you declare all the functionsyou use that never return as @code{noreturn}.  @xref{FunctionAttributes}.@item -Wreorder (C++ only)@cindex reordering, warning

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -