📄 gcc.texi
字号:
@smallexample-fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5@end smallexample@itemOn the WE32k, you may find that programs compiled with GNU CC do notwork with the standard shared C ilbrary. You may need to link withthe ordinary C compiler. If you do so, you must specify the followingoptions:@smallexample-L/usr/local/lib/gcc-lib/we32k-att-sysv/2.3 -lgcc -lc_s@end smallexampleThe first specifies where to find the library @file{libgcc.a}specified with the @samp{-lgcc} option.GNU CC does linking by invoking @code{ld}, just as @code{cc} does, andthere is no reason why it @emph{should} matter which compilation programyou use to invoke @code{ld}. If someone tracks this problem down,it can probably be fixed easily.@end itemize@node Incompatibilities@section Incompatibilities of GNU CC@cindex incompatibilities of GNU CCThere are several noteworthy incompatibilities between GNU C and mostexisting (non-ANSI) versions of C. The @samp{-traditional} optioneliminates many of these incompatibilities, @emph{but not all}, bytelling GNU C to behave like the other C compilers.@itemize @bullet@cindex string constants@cindex read-only strings@cindex shared strings@itemGNU CC normally makes string constants read-only. If severalidentical-looking string constants are used, GNU CC stores only onecopy of the string.@cindex @code{mktemp}, and constant stringsOne consequence is that you cannot call @code{mktemp} with a stringconstant argument. The function @code{mktemp} always alters thestring its argument points to.@cindex @code{sscanf}, and constant strings@cindex @code{fscanf}, and constant strings@cindex @code{scanf}, and constant stringsAnother consequence is that @code{sscanf} does not work on some systemswhen passed a string constant as its format control string or input.This is because @code{sscanf} incorrectly tries to write into the stringconstant. Likewise @code{fscanf} and @code{scanf}.The best solution to these problems is to change the program to use@code{char}-array variables with initialization strings for thesepurposes instead of string constants. But if this is not possible,you can use the @samp{-fwritable-strings} flag, which directs GNU CCto handle string constants the same way most C compilers do.@samp{-traditional} also has this effect, among others.@item@code{-2147483648} is positive.This is because 2147483648 cannot fit in the type @code{int}, so(following the ANSI C rules) its data type is @code{unsigned long int}.Negating this value yields 2147483648 again.@itemGNU CC does not substitute macro arguments when they appear inside ofstring constants. For example, the following macro in GNU CC@example#define foo(a) "a"@end example@noindentwill produce output @code{"a"} regardless of what the argument @var{a} is.The @samp{-traditional} option directs GNU CC to handle such cases(among others) in the old-fashioned (non-ANSI) fashion.@cindex @code{setjmp} incompatibilities@cindex @code{longjmp} incompatibilities@itemWhen you use @code{setjmp} and @code{longjmp}, the only automaticvariables guaranteed to remain valid are those declared@code{volatile}. This is a consequence of automatic registerallocation. Consider this function:@examplejmp_buf j;foo ()@{ int a, b; a = fun1 (); if (setjmp (j)) return a; a = fun2 (); /* @r{@code{longjmp (j)} may occur in @code{fun3}.} */ return a + fun3 ();@}@end exampleHere @code{a} may or may not be restored to its first value when the@code{longjmp} occurs. If @code{a} is allocated in a register, thenits first value is restored; otherwise, it keeps the last value storedin it.If you use the @samp{-W} option with the @samp{-O} option, you willget a warning when GNU CC thinks such a problem might be possible.The @samp{-traditional} option directs GNU C to put variables inthe stack by default, rather than in registers, in functions thatcall @code{setjmp}. This results in the behavior found intraditional C compilers.@itemPrograms that use preprocessor directives in the middle of macroarguments do not work with GNU CC. For example, a program like thiswill not work:@examplefoobar (#define luser hack)@end exampleANSI C does not permit such a construct. It would make sense to supportit when @samp{-traditional} is used, but it is too much work toimplement.@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.The @samp{-traditional} option directs GNU C to treat all @code{extern}declarations as global, like traditional compilers.@itemIn traditional C, you can combine @code{long}, etc., with a typedef name,as shown here:@exampletypedef int foo;typedef long foo bar;@end exampleIn ANSI C, this is not allowed: @code{long} and other type modifiersrequire an explicit @code{int}. Because this criterion is expressedby Bison grammar rules rather than C code, the @samp{-traditional}flag cannot alter it.@cindex typedef names as function parameters@itemPCC allows typedef names to be used as function parameters. Thedifficulty described immediately above applies here too.@cindex whitespace@itemPCC allows whitespace in the middle of compound assignment operatorssuch as @samp{+=}. GNU CC, following the ANSI standard, does notallow this. The difficulty described immediately above applies heretoo.@cindex apostrophes@cindex '@itemGNU CC complains about unterminated character constants inside ofpreprocessor conditionals that fail. Some programs have Englishcomments enclosed in conditionals that are guaranteed to fail; if thesecomments contain apostrophes, GNU CC will probably report an error. Forexample, this code would produce an error:@example#if 0You can't expect this to work.#endif@end exampleThe best solution to such a problem is to put the text into an actualC comment delimited by @samp{/*@dots{}*/}. However,@samp{-traditional} suppresses these error messages.@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 ANSI 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 @code{time_t} as the returntype of @code{time}.@cindex @code{float} as function value type@itemWhen compiling functions that return @code{float}, PCC converts it toa double. GNU CC 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, GNU CCoutput code normally uses a method different from that used on mostversions of Unix. As a result, code compiled with GNU CC cannot calla structure-returning function compiled with PCC, and vice versa.The method used by GNU CC 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 machine-description macros @code{STRUCT_VALUE} and@code{STRUCT_INCOMING_VALUE} tell GNU CC 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. GNU CC does not use this method because it isslower and nonreentrant.On some newer machines, PCC uses a reentrant convention for allstructure and union returning. GNU CC on most of these machines uses acompatible convention when returning structures and unions in memory,but still returns small structures and unions in registers.You can tell GNU CC to use a compatible convention for all structure andunion returning with the option @samp{-fpcc-struct-return}.@end itemize@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 GNU CC 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 GNU CC 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 GNU CC reports an error for codelike this:@exampleint foo (struct mumble *);struct mumble @{ @dots{} @};int foo (struct mumble *x)@{ @dots{} @}@end exampleThis 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 ANSI 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 ANSI C just to avoid an error for the exampleshown above.@itemAccesses to bitfields 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 bitfield; it may evenvary for a given bitfield according to the precise usage.If you care about controlling the amount of memory that is accessed, usevolatile but do not use bitfields.@itemOn 68000 systems, you can get paradoxical results if you test theprecise values of floating point numbers. For example, you can findthat a floating point value which is not a NaN is not equal to itself.This results from the fact that the the floating point registers hold afew 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.You can partially avoid this problem by using the option@samp{-ffloat-store} (@pxref{Optimize Options}).@itemOn the MIPS, variable argument functions using @file{varargs.h}cannot have a floating point value for the first argument. Thereason for this is that in the absence of a prototype in scope,if the first argument is a floating point, it is passed in afloating point register, rather than an integer resgister.If the code is rewritten to use the ANSI standard @file{stdarg.h}method of variable arguments, and the prototype is in scope atthe time of the call, everything will work fine.@end itemize@node Protoize Caveats@section Caveats of using @code{protoize}The conversion programs @code{protoize} and @code{unprotoize} cansometimes change a source file in a way that won't work unless yourearrange it.@itemize @bullet@item@code{protoize} can insert references to a type name or type tag beforethe definition, or in a fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -