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

📄 trouble.texi

📁 理解和实践操作系统的一本好书
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
@item@command{protoize} cannot get the argument types for a function whosedefinition was not actually compiled due to preprocessing conditionals.When this happens, @command{protoize} changes nothing in regard to sucha function.  @command{protoize} tries to detect such instances and warnabout them.You can generally work around this problem by using @command{protoize} stepby step, each time specifying a different set of @option{-D} options forcompilation, until all of the functions have been converted.  There isno automatic way to verify that you have got them all, however.@itemConfusion may result if there is an occasion to convert a functiondeclaration or definition in a region of source code where there is morethan one formal parameter list present.  Thus, attempts to convert codecontaining multiple (conditionally compiled) versions of a singlefunction header (in the same vicinity) may not produce the desired (orexpected) results.If you plan on converting source files which contain such code, it isrecommended that you first make sure that each conditionally compiledregion of source code which contains an alternative function header alsocontains at least one additional follower token (past the final rightparenthesis of the function header).  This should circumvent theproblem.@item@command{unprotoize} can become confused when trying to convert a functiondefinition or declaration which contains a declaration for apointer-to-function formal argument which has the same name as thefunction being defined or declared.  We recommend you avoid such choicesof formal parameter names.@itemYou might also want to correct some of the indentation by hand and breaklong lines.  (The conversion programs don't write lines longer thaneighty characters in any case.)@end itemize@node Non-bugs@section Certain Changes We Don't Want to MakeThis section lists changes that people frequently request, but whichwe do not make because we think GCC is better without them.@itemize @bullet@itemChecking the number and type of arguments to a function which has anold-fashioned definition and no prototype.Such a feature would work only occasionally---only for calls that appearin the same file as the called function, following the definition.  Theonly way to check all calls reliably is to add a prototype for thefunction.  But adding a prototype eliminates the motivation for thisfeature.  So the feature is not worthwhile.@itemWarning about using an expression whose type is signed as a shift count.Shift count operands are probably signed more often than unsigned.Warning about this would cause far more annoyance than good.@itemWarning about assigning a signed value to an unsigned variable.Such assignments must be very common; warning about them would causemore annoyance than good.@itemWarning when a non-void function value is ignored.C contains many standard functions that return a value that mostprograms choose to ignore.  One obvious example is @code{printf}.Warning about this practice only leads the defensive programmer toclutter programs with dozens of casts to @code{void}.  Such casts arerequired so frequently that they become visual noise.  Writing thosecasts becomes so automatic that they no longer convey usefulinformation about the intentions of the programmer.  For functionswhere the return value should never be ignored, use the@code{warn_unused_result} function attribute (@pxref{FunctionAttributes}).@item@opindex fshort-enumsMaking @option{-fshort-enums} the default.This would cause storage layout to be incompatible with most other Ccompilers.  And it doesn't seem very important, given that you can getthe same result in other ways.  The case where it matters most is whenthe enumeration-valued object is inside a structure, and in that caseyou can specify a field width explicitly.@itemMaking bit-fields unsigned by default on particular machines where ``theABI standard'' says to do so.The ISO C standard leaves it up to the implementation whether a bit-fielddeclared plain @code{int} is signed or not.  This in effect creates twoalternative dialects of C@.@opindex fsigned-bitfields@opindex funsigned-bitfieldsThe GNU C compiler supports both dialects; you can specify the signeddialect with @option{-fsigned-bitfields} and the unsigned dialect with@option{-funsigned-bitfields}.  However, this leaves open the question ofwhich dialect to use by default.Currently, the preferred dialect makes plain bit-fields signed, becausethis is simplest.  Since @code{int} is the same as @code{signed int} inevery other context, it is cleanest for them to be the same in bit-fieldsas well.Some computer manufacturers have published Application Binary Interfacestandards which specify that plain bit-fields should be unsigned.  It isa mistake, however, to say anything about this issue in an ABI@.  This isbecause the handling of plain bit-fields distinguishes two dialects of C@.Both dialects are meaningful on every type of machine.  Whether aparticular object file was compiled using signed bit-fields or unsignedis of no concern to other object files, even if they access the samebit-fields in the same data structures.A given program is written in one or the other of these two dialects.The program stands a chance to work on most any machine if it iscompiled with the proper dialect.  It is unlikely to work at all ifcompiled with the wrong dialect.Many users appreciate the GNU C compiler because it provides anenvironment that is uniform across machines.  These users would beinconvenienced if the compiler treated plain bit-fields differently oncertain machines.Occasionally users write programs intended only for a particular machinetype.  On these occasions, the users would benefit if the GNU C compilerwere to support by default the same dialect as the other compilers onthat machine.  But such applications are rare.  And users writing aprogram to run on more than one type of machine cannot possibly benefitfrom this kind of compatibility.This is why GCC does and will treat plain bit-fields in the samefashion on all types of machines (by default).There are some arguments for making bit-fields unsigned by default on allmachines.  If, for example, this becomes a universal de facto standard,it would make sense for GCC to go along with it.  This is somethingto be considered in the future.(Of course, users strongly concerned about portability should indicateexplicitly in each bit-field whether it is signed or not.  In this way,they write programs which have the same meaning in both C dialects.)@item@opindex ansi@opindex stdUndefining @code{__STDC__} when @option{-ansi} is not used.Currently, GCC defines @code{__STDC__} unconditionally.  This providesgood results in practice.Programmers normally use conditionals on @code{__STDC__} to ask whetherit is safe to use certain features of ISO C, such as functionprototypes or ISO token concatenation.  Since plain @command{gcc} supportsall the features of ISO C, the correct answer to these questions is``yes''.Some users try to use @code{__STDC__} to check for the availability ofcertain library facilities.  This is actually incorrect usage in an ISOC program, because the ISO C standard says that a conformingfreestanding implementation should define @code{__STDC__} even though itdoes not have the library facilities.  @samp{gcc -ansi -pedantic} is aconforming freestanding implementation, and it is therefore required todefine @code{__STDC__}, even though it does not come with an ISO Clibrary.Sometimes people say that defining @code{__STDC__} in a compiler thatdoes not completely conform to the ISO C standard somehow violates thestandard.  This is illogical.  The standard is a standard for compilersthat claim to support ISO C, such as @samp{gcc -ansi}---not for othercompilers such as plain @command{gcc}.  Whatever the ISO C standard saysis relevant to the design of plain @command{gcc} without @option{-ansi} onlyfor pragmatic reasons, not as a requirement.GCC normally defines @code{__STDC__} to be 1, and in additiondefines @code{__STRICT_ANSI__} if you specify the @option{-ansi} option,or a @option{-std} option for strict conformance to some version of ISO C@.On some hosts, system include files use a different convention, where@code{__STDC__} is normally 0, but is 1 if the user specifies strictconformance to the C Standard.  GCC follows the host convention whenprocessing system include files, but when processing user files it followsthe usual GNU C convention.@itemUndefining @code{__STDC__} in C++.Programs written to compile with C++-to-C translators get thevalue of @code{__STDC__} that goes with the C compiler that issubsequently used.  These programs must test @code{__STDC__}to determine what kind of C preprocessor that compiler uses:whether they should concatenate tokens in the ISO C fashionor in the traditional fashion.These programs work properly with GNU C++ if @code{__STDC__} is defined.They would not work otherwise.In addition, many header files are written to provide prototypes in ISOC but not in traditional C@.  Many of these header files can work withoutchange in C++ provided @code{__STDC__} is defined.  If @code{__STDC__}is not defined, they will all fail, and will all need to be changed totest explicitly for C++ as well.@itemDeleting ``empty'' loops.Historically, GCC has not deleted ``empty'' loops under theassumption that the most likely reason you would put one in a program isto have a delay, so deleting them will not make real programs run anyfaster.However, the rationale here is that optimization of a nonempty loopcannot produce an empty one. This held for carefully written C compiledwith less powerful optimizers but is not always the case for carefullywritten C++ or with more powerful optimizers.Thus GCC will remove operations from loops whenever it can determinethose operations are not externally visible (apart from the time takento execute them, of course).  In case the loop can be proved to be finite,GCC will also remove the loop itself.Be aware of this when performing timing tests, for instance thefollowing loop can be completely removed, provided@code{some_expression} can provably not change any global state.@smallexample@{   int sum = 0;   int ix;   for (ix = 0; ix != 10000; ix++)      sum += some_expression;@}@end smallexampleEven though @code{sum} is accumulated in the loop, no use is made ofthat summation, so the accumulation can be removed.@itemMaking side effects happen in the same order as in some other compiler.@cindex side effects, order of evaluation@cindex order of evaluation, side effectsIt is never safe to depend on the order of evaluation of side effects.For example, a function call like this may very well behave differentlyfrom one compiler to another:@smallexamplevoid func (int, int);int i = 2;func (i++, i++);@end smallexampleThere is no guarantee (in either the C or the C++ standard languagedefinitions) that the increments will be evaluated in any particularorder.  Either increment might happen first.  @code{func} might get thearguments @samp{2, 3}, or it might get @samp{3, 2}, or even @samp{2, 2}.@itemMaking certain warnings into errors by default.Some ISO C testsuites report failure when the compiler does not producean error message for a certain program.@opindex pedantic-errorsISO C requires a ``diagnostic'' message for certain kinds of invalidprograms, but a warning is defined by GCC to count as a diagnostic.  IfGCC produces a warning but not an error, that is correct ISO C support.If testsuites call this ``failure'', they should be run with the GCCoption @option{-pedantic-errors}, which will turn these warnings intoerrors.@end itemize@node Warnings and Errors@section Warning Messages and Error Messages@cindex error messages@cindex warnings vs errors@cindex messages, warning and errorThe GNU compiler can produce two kinds of diagnostics: errors andwarnings.  Each kind has a different purpose:@itemize @w{}@item@dfn{Errors} report problems that make it impossible to compile yourprogram.  GCC reports errors with the source file name and linenumber where the problem is apparent.@item@dfn{Warnings} report other unusual conditions in your code that@emph{may} indicate a problem, although compilation can (and does)proceed.  Warning messages also report the source file name and linenumber, but include the text @samp{warning:} to distinguish themfrom error messages.@end itemizeWarnings may indicate danger points where you should check to make surethat your program really does what you intend; or the use of obsoletefeatures; or the use of nonstandard features of GNU C or C++.  Manywarnings are issued only if you ask for them, with one of the @option{-W}options (for instance, @option{-Wall} requests a variety of usefulwarnings).@opindex pedantic@opindex pedantic-errorsGCC always tries to compile your program if possible; it nevergratuitously rejects a program whose meaning is clear merely because(for instance) it fails to conform to a standard.  In some cases,however, the C and C++ standards specify that certain extensions areforbidden, and a diagnostic @emph{must} be issued by a conformingcompiler.  The @option{-pedantic} option tells GCC to issue warnings insuch cases; @option{-pedantic-errors} says to make them errors instead.This does not mean that @emph{all} non-ISO constructs get warningsor errors.@xref{Warning Options,,Options to Request or Suppress Warnings}, formore detail on these and related command-line options.

⌨️ 快捷键说明

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