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

📄 trouble.texi

📁 理解和实践操作系统的一本好书
💻 TEXI
📖 第 1 页 / 共 4 页
字号:
@smallexample@groupfoobar (#define luser        hack)@end group@end smallexampleISO C does not permit such a construct.@itemK&R compilers allow comments to cross over an inclusion boundary(i.e.@: started in an include file and ended in the including file).@cindex external declaration scope@cindex scope of external declarations@cindex declaration scope@itemDeclarations of external variables and functions within a block applyonly to the block containing the declaration.  In other words, theyhave the same scope as any other declaration in the same place.In some other C compilers, a @code{extern} declaration affects all therest of the file even if it happens within a block.@itemIn traditional C, you can combine @code{long}, etc., with a typedef name,as shown here:@smallexampletypedef int foo;typedef long foo bar;@end smallexampleIn ISO C, this is not allowed: @code{long} and other type modifiersrequire an explicit @code{int}.@cindex typedef names as function parameters@itemPCC allows typedef names to be used as function parameters.@itemTraditional C allows the following erroneous pair of declarations toappear together in a given scope:@smallexampletypedef int foo;typedef foo foo;@end smallexample@itemGCC treats all characters of identifiers as significant.  According toK&R-1 (2.2), ``No more than the first eight characters are significant,although more may be used.''.  Also according to K&R-1 (2.2), ``Anidentifier is a sequence of letters and digits; the first character mustbe a letter.  The underscore _ counts as a letter.'', but GCC alsoallows dollar signs in identifiers.@cindex whitespace@itemPCC allows whitespace in the middle of compound assignment operatorssuch as @samp{+=}.  GCC, following the ISO standard, does notallow this.@cindex apostrophes@cindex '@itemGCC complains about unterminated character constants inside ofpreprocessing conditionals that fail.  Some programs have Englishcomments enclosed in conditionals that are guaranteed to fail; if thesecomments contain apostrophes, GCC will probably report an error.  Forexample, this code would produce an error:@smallexample#if 0You can't expect this to work.#endif@end smallexampleThe best solution to such a problem is to put the text into an actualC comment delimited by @samp{/*@dots{}*/}.@itemMany user programs contain the declaration @samp{long time ();}.  In thepast, the system header files on many systems did not actually declare@code{time}, so it did not matter what type your program declared it toreturn.  But in systems with ISO C headers, @code{time} is declared toreturn @code{time_t}, and if that is not the same as @code{long}, then@samp{long time ();} is erroneous.The solution is to change your program to use appropriate system headers(@code{<time.h>} on systems with ISO C headers) and not to declare@code{time} if the system header files declare it, or failing that touse @code{time_t} as the return type of @code{time}.@cindex @code{float} as function value type@itemWhen compiling functions that return @code{float}, PCC converts it toa double.  GCC actually returns a @code{float}.  If you are concernedwith PCC compatibility, you should declare your functions to return@code{double}; you might as well say what you mean.@cindex structures@cindex unions@itemWhen compiling functions that return structures or unions, GCCoutput code normally uses a method different from that used on mostversions of Unix.  As a result, code compiled with GCC cannot calla structure-returning function compiled with PCC, and vice versa.The method used by GCC is as follows: a structure or union which is1, 2, 4 or 8 bytes long is returned like a scalar.  A structure or unionwith any other size is stored into an address supplied by the caller(usually in a special, fixed register, but on some machines it is passedon the stack).  The target hook @code{TARGET_STRUCT_VALUE_RTX}tells GCC where to pass this address.By contrast, PCC on most target machines returns structures and unionsof any size by copying the data into an area of static storage, and thenreturning the address of that storage as if it were a pointer value.The caller must copy the data from that memory area to the place wherethe value is wanted.  GCC does not use this method because it isslower and nonreentrant.On some newer machines, PCC uses a reentrant convention for allstructure and union returning.  GCC on most of these machines uses acompatible convention when returning structures and unions in memory,but still returns small structures and unions in registers.@opindex fpcc-struct-returnYou can tell GCC to use a compatible convention for all structure andunion returning with the option @option{-fpcc-struct-return}.@cindex preprocessing tokens@cindex preprocessing numbers@itemGCC complains about program fragments such as @samp{0x74ae-0x4000}which appear to be two hexadecimal constants separated by the minusoperator.  Actually, this string is a single @dfn{preprocessing token}.Each such token must correspond to one token in C@.  Since this does not,GCC prints an error message.  Although it may appear obvious that whatis meant is an operator and two values, the ISO C standard specificallyrequires that this be treated as erroneous.A @dfn{preprocessing token} is a @dfn{preprocessing number} if itbegins with a digit and is followed by letters, underscores, digits,periods and @samp{e+}, @samp{e-}, @samp{E+}, @samp{E-}, @samp{p+},@samp{p-}, @samp{P+}, or @samp{P-} character sequences.  (In strict C89mode, the sequences @samp{p+}, @samp{p-}, @samp{P+} and @samp{P-} cannotappear in preprocessing numbers.)To make the above program fragment valid, place whitespace in front ofthe minus sign.  This whitespace will end the preprocessing number.@end itemize@node Fixed Headers@section Fixed Header FilesGCC needs to install corrected versions of some system header files.This is because most target systems have some header files that won'twork with GCC unless they are changed.  Some have bugs, some areincompatible with ISO C, and some depend on special features of othercompilers.Installing GCC automatically creates and installs the fixed headerfiles, by running a program called @code{fixincludes}.  Normally, youdon't need to pay attention to this.  But there are cases where itdoesn't do the right thing automatically.@itemize @bullet@itemIf you update the system's header files, such as by installing a newsystem version, the fixed header files of GCC are not automaticallyupdated.  They can be updated using the @command{mkheaders} scriptinstalled in@file{@var{libexecdir}/gcc/@var{target}/@var{version}/install-tools/}.@itemOn some systems, header file directories containmachine-specific symbolic links in certain places.  This makes itpossible to share most of the header files among hosts running thesame version of the system on different machine models.The programs that fix the header files do not understand this specialway of using symbolic links; therefore, the directory of fixed headerfiles is good only for the machine model used to build it.It is possible to make separate sets of fixed header files for thedifferent machine models, and arrange a structure of symbolic links soas to use the proper set, but you'll have to do this by hand.@end itemize@node Standard Libraries@section Standard Libraries@opindex WallGCC by itself attempts to be a conforming freestanding implementation.@xref{Standards,,Language Standards Supported by GCC}, for details ofwhat this means.  Beyond the library facilities required of such animplementation, the rest of the C library is supplied by the vendor ofthe operating system.  If that C library doesn't conform to the Cstandards, then your programs might get warnings (especially when using@option{-Wall}) that you don't expect.For example, the @code{sprintf} function on SunOS 4.1.3 returns@code{char *} while the C standard says that @code{sprintf} returns an@code{int}.  The @code{fixincludes} program could make the prototype forthis function match the Standard, but that would be wrong, since thefunction will still return @code{char *}.If you need a Standard compliant library, then you need to find one, asGCC does not provide one.  The GNU C library (called @code{glibc})provides ISO C, POSIX, BSD, SystemV and X/Open compatibility forGNU/Linux and HURD-based GNU systems; no recent version of it supportsother systems, though some very old versions did.  Version 2.2 of theGNU C library includes nearly complete C99 support.  You could also askyour operating system vendor if newer libraries are available.@node Disappointments@section Disappointments and MisunderstandingsThese problems are perhaps regrettable, but we don't know any practicalway around them.@itemize @bullet@itemCertain local variables aren't recognized by debuggers when you compilewith optimization.This occurs because sometimes GCC optimizes the variable out ofexistence.  There is no way to tell the debugger how to compute thevalue such a variable ``would have had'', and it is not clear that wouldbe desirable anyway.  So GCC simply does not mention the eliminatedvariable when it writes debugging information.You have to expect a certain amount of disagreement between theexecutable and your source code, when you use optimization.@cindex conflicting types@cindex scope of declaration@itemUsers often think it is a bug when GCC reports an error for codelike this:@smallexampleint foo (struct mumble *);struct mumble @{ @dots{} @};int foo (struct mumble *x)@{ @dots{} @}@end smallexampleThis code really is erroneous, because the scope of @code{structmumble} in the prototype is limited to the argument list containing it.It does not refer to the @code{struct mumble} defined with file scopeimmediately below---they are two unrelated types with similar names indifferent scopes.But in the definition of @code{foo}, the file-scope type is usedbecause that is available to be inherited.  Thus, the definition andthe prototype do not match, and you get an error.This behavior may seem silly, but it's what the ISO standard specifies.It is easy enough for you to make your code work by moving thedefinition of @code{struct mumble} above the prototype.  It's not worthbeing incompatible with ISO C just to avoid an error for the exampleshown above.@itemAccesses to bit-fields even in volatile objects works by accessing largerobjects, such as a byte or a word.  You cannot rely on what size ofobject is accessed in order to read or write the bit-field; it may evenvary for a given bit-field according to the precise usage.If you care about controlling the amount of memory that is accessed, usevolatile but do not use bit-fields.@itemGCC comes with shell scripts to fix certain known problems in systemheader files.  They install corrected copies of various header files ina special directory where only GCC will normally look for them.  Thescripts adapt to various systems by searching all the system headerfiles for the problem cases that we know about.If new system header files are installed, nothing automatically arrangesto update the corrected header files.  They can be updated using the@command{mkheaders} script installed in@file{@var{libexecdir}/gcc/@var{target}/@var{version}/install-tools/}.@item@cindex floating point precisionOn 68000 and x86 systems, for instance, you can get paradoxical resultsif you test the precise values of floating point numbers.  For example,you can find that a floating point value which is not a NaN is not equalto itself.  This results from the fact that the floating point registershold a few more bits of precision than fit in a @code{double} in memory.Compiled code moves values between memory and floating point registersat its convenience, and moving them into memory truncates them.@opindex ffloat-storeYou can partially avoid this problem by using the @option{-ffloat-store}option (@pxref{Optimize Options}).@itemOn AIX and other platforms without weak symbol support, templatesneed to be instantiated explicitly and symbols for static membersof templates will not be generated.@itemOn AIX, GCC scans object files and library archives for staticconstructors and destructors when linking an application before thelinker prunes unreferenced symbols.  This is necessary to prevent theAIX linker from mistakenly assuming that static constructor ordestructor are unused and removing them before the scanning can occur.All static constructors and destructors found will be referenced eventhough the modules in which they occur may not be used by the program.This may lead to both increased executable size and unexpected symbolreferences.@end itemize@node C++ Misunderstandings@section Common Misunderstandings with GNU C++@cindex misunderstandings in C++@cindex surprises in C++@cindex C++ misunderstandingsC++ is a complex language and an evolving one, and its standard

⌨️ 快捷键说明

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