📄 gcc.1
字号:
Warnings are diagnostic messages that report constructions whichare not inherently erroneous but which are risky or suggest theremay have been an error..SpThese options control the amount and kinds of warnings produced by GNUCC:.TP.B \-fsyntax\-onlyCheck the code for syntax errors, but don't emit any output..TP.B \-wInhibit all warning messages..TP.B \-Wno\-importInhibit warning messages about the use of.BR #import ..TP.B \-pedanticIssue all the warnings demanded by strict ANSI standard C; rejectall programs that use forbidden extensions..SpValid ANSI standard C programs should compile properly with or withoutthis option (though a rare few will require `\|\c.B \-ansi\c\&\|'). However,without this option, certain GNU extensions and traditional C featuresare supported as well. With this option, they are rejected. There isno reason to \c.I use\c\& this option; it exists only to satisfy pedants..Sp`\|\c.B \-pedantic\c\&\|' does not cause warning messages for use of thealternate keywords whose names begin and end with `\|\c.B _\|_\c\&\|'. Pedanticwarnings are also disabled in the expression that follows.B _\|_extension_\|_\c\&. However, only system header files should usethese escape routes; application programs should avoid them..TP.B \-pedantic\-errorsLike `\|\c.B \-pedantic\c\&\|', except that errors are produced rather thanwarnings..TP.B \-WPrint extra warning messages for these events:.TP\ \ \ \(buA nonvolatile automatic variable might be changed by a call to.B longjmp\c\&. These warnings are possible only inoptimizing compilation..SpThe compiler sees only the calls to \c.B setjmp\c\&. It cannot knowwhere \c.B longjmp\c\& 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 \c.B longjmp\c\& cannotin fact be called at the place which would cause a problem..TP\ \ \ \(buA 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:.Sp.nffoo (a){ if (a > 0) return a;}.Sp.fiSpurious warnings can occur because GNU CC does not realize thatcertain functions (including \c.B abort\c\& and \c.B longjmp\c\&)will never return..TP\ \ \ \(buAn 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 `\|\c.B x[i,j]\c\&\|' will cause a warning,but `\|\c.B x[(void)i,j]\c\&\|' will not..TP\ \ \ \(buAn unsigned value is compared against zero with `\|\c.B >\c\&\|' or `\|\c.B <=\c\&\|'..PP.TP.B \-Wimplicit-intWarn whenever a declaration does not specify a type..TP.B \-Wimplicit-function-declarationWarn whenever a function is used before being declared..TP.B \-WimplicitSame as -Wimplicit-int and -Wimplicit-function-declaration..TP.B \-WmainWarn if the.B mainfunction is declared or defined with a suspicious type.Typically, it is a function with external linkage, returning.B int\c\&, andtaking zero or two arguments..TP.B \-Wreturn\-typeWarn whenever a function is defined with a return-type that defaultsto \c.B int\c\&. Also warn about any \c.B return\c\& statement with noreturn-value in a function whose return-type is not \c.B void\c\&..TP.B \-WunusedWarn whenever a local variable is unused aside from its declaration,whenever a function is declared static but never defined, and whenevera statement computes a result that is explicitly not used..TP.B \-WswitchWarn whenever a \c.B switch\c\& statement has an index of enumeral typeand lacks a \c.B case\c\& for one or more of the named codes of thatenumeration. (The presence of a \c.B default\c\& label prevents thiswarning.) \c.B case\c\& labels outside the enumeration range alsoprovoke warnings when this option is used..TP.B \-WcommentWarn whenever a comment-start sequence `\|\c.B /\(**\c\&\|' appears in a comment..TP.B \-WtrigraphsWarn if any trigraphs are encountered (assuming they are enabled)..TP.B \-WformatCheck calls to \c.B printf\c\& and \c.B scanf\c\&, etc., to make sure thatthe arguments supplied have types appropriate to the format stringspecified..TP.B \-Wchar\-subscriptsWarn if an array subscript has type.BR char .This is a common cause of error, as programmers often forget that thistype is signed on some machines..TP.B \-WuninitializedAn automatic variable is used without first being initialized..SpThese warnings are possible only in optimizing compilation,because they require data flow information that is computed onlywhen optimizing. If you don't specify `\|\c.B \-O\c\&\|', you simply won'tget these warnings..SpThese warnings occur only for variables that are candidates forregister allocation. Therefore, they do not occur for a variable thatis declared \c.B volatile\c\&, 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..SpNote 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..SpThese 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:.Sp.nf{ int x; switch (y) { case 1: x = 1; break; case 2: x = 4; break; case 3: x = 5; } foo (x);}.Sp.fiIf the value of \c.B y\c\& is always 1, 2 or 3, then \c.B x\c\& isalways initialized, but GNU CC doesn't know this. Here isanother common case:.Sp.nf{ int save_y; if (change_y) save_y = y, y = new_y; .\|.\|. if (change_y) y = save_y;}.Sp.fiThis has no bug because \c.B save_y\c\& is used only if it is set..SpSome spurious warnings can be avoided if you declare as.B volatile\c\& all the functions you use that never return..TP.B \-WparenthesesWarn if parentheses are omitted in certain contexts..TP.B \-Wtemplate\-debuggingWhen using templates in a C++ program, warn if debugging is not yetfully available (C++ only)..TP.B \-WallAll of the above `\|\c.B \-W\c\&\|' 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..PPThe remaining `\|\c.B \-W.\|.\|.\c\&\|' options are not implied by `\|\c.B \-Wall\c\&\|'because they warn about constructions that we consider reasonable touse, on occasion, in clean programs..TP.B \-WtraditionalWarn about certain constructs that behave differently in traditional andANSI C..TP\ \ \ \(buMacro 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..TP\ \ \ \(buA function declared external in one block and then used after the end ofthe block..TP\ \ \ \(buA \c.B switch\c\& statement has an operand of type \c.B long\c\&..PP.TP.B \-WshadowWarn whenever a local variable shadows another local variable..TP.BI "\-Wid\-clash\-" "len"Warn whenever two distinct identifiers match in the first \c.I lencharacters. This may help you prepare a program that will compilewith certain obsolete, brain-damaged compilers..TP.B \-Wpointer\-arithWarn about anything that depends on the \*(lqsize of\*(rq a function type orof \c.B void\c\&. GNU C assigns these types a size of 1, forconvenience in calculations with \c.B void \(**\c\& pointers and pointersto functions..TP.B \-Wcast\-qualWarn whenever a pointer is cast so as to remove a type qualifier fromthe target type. For example, warn if a \c.B const char \(**\c\& is castto an ordinary \c.B char \(**\c\&..TP.B \-Wcast\-alignWarn whenever a pointer is cast such that the required alignment of thetarget is increased. For example, warn if a \c.B char \(**\c\& is cast toan \c.B int \(**\c\& on machines where integers can only be accessed attwo- or four-byte boundaries..TP.B \-Wwrite\-stringsGive string constants the type \c.B const char[\c.I length\c.B ]\c\& so thatcopying the address of one into a non-\c.B const\c\& \c.B char \(**pointer will get a warning. These warnings will help you find atcompile time code that can try to write into a string constant, butonly if you have been very careful about using \c.B const\c\& indeclarations and prototypes. Otherwise, it will just be a nuisance;this is why we did not make `\|\c.B \-Wall\c\&\|' request these warnings..TP.B \-WconversionWarn if a prototype causes a type conversion that is different from whatwould happen to the same argument in the absence of a prototype. Thisincludes conversions of fixed point to floating and vice versa, andconversions changing the width or signedness of a fixed point argumentexcept when the same as the default promotion..TP.B \-Waggregate\-returnWarn if any functions that return structures or unions are defined orcalled. (In languages where you can return an array, this also elicitsa warning.).TP.B \-Wstrict\-prototypesWarn if a function is declared or defined without specifying theargument types. (An old-style function definition is permitted withouta warning if preceded by a declaration which specifies the argumenttypes.).TP.B \-Wmissing\-prototypesWarn if a global function is defined without a previous prototypedeclaration. This warning is issued even if the definition itselfprovides a prototype. The aim is to detect global functions that failto be declared in header files..TP.B \-Wmissing\-declarationsWarn if a global function is defined without a previous declaration.Do so even if the definition itself provides a prototype.Use this option to detect global functions that are not declared inheader files..TP.B \-Wredundant-declsWarn if anything is declared more than once in the same scope, even incases where multiple declaration is valid and changes nothing..TP.B \-Wnested-externsWarn if an \c.B extern\c\& declaration is encountered within an function..TP.B \-Wenum\-clashWarn about conversion between different enumeration types (C++ only)..TP.B \-Woverloaded\-virtual(C++ only.)In a derived class, the definitions of virtual functions must matchthe type signature of a virtual function declared in the base class.Use this option to request warnings when a derived class declares afunction that may be an erroneous attempt to define a virtualfunction: that is, warn when a function with the same name as avirtual function in the base class, but with a type signature thatdoesn't match any virtual functions from the base class..TP.B \-WinlineWarn if a function can not be inlined, and either it was declared as inline,or else the.B \-finline\-functionsoption was given..TP.B \-WerrorTreat warnings as errors; abort compilation after any warning..SH DEBUGGING OPTIONSGNU CC has various special options that are used for debuggingeither your program or GCC:.TP.B \-gProduce debugging information in the operating system's native format(stabs, COFF, XCOFF, or DWARF). GDB can work with this debugginginformation..SpOn most systems that use stabs format, `\|\c.B \-g\c\&\|' enables use of extradebugging information that only GDB can use; this extra informationmakes debugging work better in GDB but will probably make other debuggerscrash orrefuse to read the program. If you want to control for certain whetherto generate the extra information, use `\|\c.B \-gstabs+\c\&\|', `\|\c.B \-gstabs\c\&\|',`\|\c.B \-gxcoff+\c\&\|', `\|\c.B \-gxcoff\c\&\|', `\|\c.B \-gdwarf+\c\&\|', or `\|\c.B \-gdwarf\c\&\|'(see below)..SpUnlike most other C compilers, GNU CC allows you to use `\|\c.B \-g\c\&\|' with`\|\c.B \-O\c\&\|'. The shortcuts taken by optimized code may occasionallyproduce surprising results: some variables you declared may not existat all; flow of control may briefly move where you did not expect it;some statements may not be executed because they compute constantresults or their values were already at hand; some statements mayexecute in different places because they were moved out of loops..SpNevertheless it proves possible to debug optimized output. This makesit reasonable to use the optimizer for programs that might have bugs..PPThe following options are useful when GNU CC is generated with thecapability for more than one debugging format..TP.B \-ggdbProduce debugging information in the native format (if that is supported),including GDB extensions if at all possible..TP.B \-gstabsProduce debugging information in stabs format (if that is supported),without GDB extensions. This is the format used by DBX on most BSDsystems..TP.B \-gstabs+Produce debugging information in stabs format (if that is supported),using GNU extensions understood only by the GNU debugger (GDB). Theuse of these extensions is likely to make other debuggers crash orrefuse to read the program..TP.B \-gcoffProduce debugging information in COFF format (if that is supported).This is the format used by SDB on most System V systems prior toSystem V Release 4..TP.B \-gxcoffProduce debugging information in XCOFF format (if that is supported).This is the format used by the DBX debugger on IBM RS/6000 systems..TP.B \-gxcoff+Produce debugging information in XCOFF format (if that is supported),using GNU extensions understood only by the GNU debugger (GDB). Theuse of these extensions is likely to make other debuggers crash orrefuse to read the program..TP.B \-gdwarfProduce debugging information in DWARF format (if that is supported).This is the format used by SDB on most System V Release 4 systems..TP.B \-gdwarf+Produce debugging information in DWARF format (if that is supported),using GNU extensions understood only by the GNU debugger (GDB). Theuse of these extensions is likely to make other debuggers crash orrefuse to read the program..PP.BI "\-g" "level".br.BI "\-ggdb" "level".br.BI "\-gstabs" "level".br.BI "\-gcoff" "level".BI "\-gxcoff" "level".TP.BI "\-gdwarf" "level"Request debugging information and also use \c.I level\c\& to specify howmuch information. The default level is 2..SpLevel 1 produces minimal information, enough for making backtraces inparts of the program that you don't plan to debug. This includesdescriptions of functions and external variables, but no informationabout local variables and no line numbers..SpLevel 3 includes extra information, such as all the macro definitionspresent in the program. Some debuggers support macro expansion whenyou use `\|\c.B \-g3\c\&\|'..TP.B \-pGenerate extra code to write profile information suitable for theanalysis program \c.B prof\c\&..TP.B \-pgGenerate extra code to write profile information suitable for theanalysis program \c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -