📄 invoke.texi
字号:
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 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 -WimplicitWarn whenever a function or parameter is implicitly declared.@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.@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.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 -Wenum-clash@cindex enumeration clash warnings@cindex warning for enumeration conversionsWarn about conversion between different enumeration types.(C++ only).@item -Wreorder (C++ only)@cindex reordering, warning@cindex warning for reordering of member initializersWarn when the order of member initializers given in the code does notmatch the order in which they must be executed. For instance:@smallexamplestruct A @{ int i; int j; A(): j (0), i (1) @{ @}@};@end smallexampleHere the compiler will warn that the member initializers for @samp{i}and @samp{j} will be rearranged to match the declaration order of themembers.@item -Wtemplate-debugging@cindex template debuggingWhen using templates in a C++ program, warn if debugging is not yetfully available (C++ only).@item -WallAll of the above @samp{-W} options combined. These are all theoptions which pertain to usage that we recommend avoiding and that webelieve is easy to avoid, even in conjunction with macros.@end tableThe remaining @samp{-W@dots{}} options are not implied by @samp{-Wall}because they warn about constructions that we consider reasonable touse, on occasion, in clean programs.@table @code@item -WPrint extra warning messages for these events:@itemize @bullet@cindex @code{longjmp} warnings@itemA nonvolatile automatic variable might be changed by a call to@code{longjmp}. These warnings as well are possible only inoptimizing compilation.The compiler sees only the calls to @code{setjmp}. It cannot knowwhere @code{longjmp} will be called; in fact, a signal handler couldcall it at any point in the code. As a result, you may get a warningeven when there is in fact no problem because @code{longjmp} cannotin fact be called at the place which would cause a problem.@itemA function can return either with or without a value. (Fallingoff the end of the function body is considered returning withouta value.) For example, this function would evoke such awarning:@smallexample@groupfoo (a)@{ if (a > 0) return a;@}@end group@end smallexample@itemAn expression-statement or the left-hand side of a comma expressioncontains no side effects. To suppress the warning, cast the unused expression to void.For example, an expression such as @samp{x[i,j]} will cause a warning,but @samp{x[(void)i,j]} will not.@itemAn unsigned value is compared against zero with @samp{<} or @samp{<=}.@itemA comparison like @samp{x<=y<=z} appears; this is equivalent to@samp{(x<=y ? 1 : 0) <= z}, which is a different interpretation fromthat of ordinary mathematical notation.@itemStorage-class specifiers like @code{static} are not the first things ina declaration. According to the C Standard, this usage is obsolescent.@itemIf @samp{-Wall} or @samp{-Wunused} is also specified, warn about unusedarguments.@itemAn aggregate has a partly bracketed initializer.For example, the following code would evoke such a warning,because braces are missing around the initializer for @code{x.h}:@smallexamplestruct s @{ int f, g; @};struct t @{ struct s h; int i; @};struct t x = @{ 1, 2, 3 @};@end smallexample@end itemize@item -WtraditionalWarn about certain constructs that behave differently in traditional andANSI C.@itemize @bullet@itemMacro arguments occurring within string constants in the macro body.These would substitute the argument in traditional C, but are part ofthe constant in ANSI C.@itemA function declared external in one block and then used after the end ofthe block.@itemA @code{switch} statement has an operand of type @code{long}.@end itemize@item -WshadowWarn whenever a local variable shadows another local variable.@item -Wid-clash-@var{len}Warn whenever two distinct identifiers match in the first @var{len}characters. This may help you prepare a program that will compilewith certain obsolete, brain-damaged compilers.@item -Wlarger-than-@var{len}Warn whenever an object of larger than @var{len} bytes is defined.@item -Wpointer-arithWarn about anything that depends on the ``size of'' a function type orof @code{void}. GNU C assigns these types a size of 1, forconvenience in calculations with @code{void *} pointers and pointersto functions.@item -Wbad-function-castWarn whenever a function call is cast to a non-matching type.For example, warn if @code{int malloc()} is cast to @code{anything *}.@item -Wcast-qualWarn whenever a pointer is cast so as to remove a type qualifier fromthe target type. For example, warn if a @code{const char *} is castto an ordinary @code{char *}.@item -Wcast-alignWarn whenever a pointer is cast such that the required alignment of thetarget is increased. For example, warn if a @code{char *} is cast toan @code{int *} on machines where integers can only be accessed attwo- or four-byte boundaries.@item -Wwrite-stringsGive string constants the type @code{const char[@var{length}]} so thatcopying the address of one into a non-@code{const} @code{char *}pointer will get a warning. These warnings will help you find atcompile time code that can try to write into a string constant, but
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -