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

📄 extend.texi

📁 gcc库的原代码,对编程有很大帮助.
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
declares @samp{f} to be a weak alias for @samp{__f}.  In C++, themangled name for the target must be used.@item regparm (@var{number})@cindex functions that are passed arguments in registers on the 386On the Intel 386, the @code{regparm} attribute causes the compiler topass up to @var{number} integer arguments in registers @var{EAX},@var{EDX}, and @var{ECX} instead of on the stack.  Functions that take avariable number of arguments will continue to be passed all of theirarguments on the stack.@item stdcall@cindex functions that pop the argument stack on the 386On the Intel 386, the @code{stdcall} attribute causes the compiler toassume that the called function will pop off the stack space used topass arguments, unless it takes a variable number of arguments.@item cdecl@cindex functions that do pop the argument stack on the 386On the Intel 386, the @code{cdecl} attribute causes the compiler toassume that the called function will pop off the stack space used topass arguments, unless it takes a variable number of arguments.  This isuseful to override the effects of the @samp{-mrtd} switch.@end tableYou can specify multiple attributes in a declaration by separating themby commas within the double parentheses or by immediately following anattribute declaration with another attribute declaration.@cindex @code{#pragma}, reason for not using@cindex pragma, reason for not usingSome people object to the @code{__attribute__} feature, suggesting that ANSI C's@code{#pragma} should be used instead.  There are two reasons for notdoing this.@enumerate@itemIt is impossible to generate @code{#pragma} commands from a macro.@itemThere is no telling what the same @code{#pragma} might mean in anothercompiler.@end enumerateThese two reasons apply to almost any application that might be proposedfor @code{#pragma}.  It is basically a mistake to use @code{#pragma} for@emph{anything}.@node Function Prototypes@section Prototypes and Old-Style Function Definitions@cindex function prototype declarations@cindex old-style function definitions@cindex promotion of formal parametersGNU C extends ANSI C to allow a function prototype to override a laterold-style non-prototype definition.  Consider the following example:@example/* @r{Use prototypes unless the compiler is old-fashioned.}  */#if __STDC__#define P(x) x#else#define P(x) ()#endif/* @r{Prototype function declaration.}  */int isroot P((uid_t));/* @r{Old-style function definition.}  */intisroot (x)   /* ??? lossage here ??? */     uid_t x;@{  return x == 0;@}@end exampleSuppose the type @code{uid_t} happens to be @code{short}.  ANSI C doesnot allow this example, because subword arguments in old-stylenon-prototype definitions are promoted.  Therefore in this example thefunction definition's argument is really an @code{int}, which does notmatch the prototype argument type of @code{short}.This restriction of ANSI C makes it hard to write code that is portableto traditional C compilers, because the programmer does not knowwhether the @code{uid_t} type is @code{short}, @code{int}, or@code{long}.  Therefore, in cases like these GNU C allows a prototypeto override a later old-style definition.  More precisely, in GNU C, afunction prototype argument type overrides the argument type specifiedby a later old-style definition if the former type is the same as thelatter type before promotion.  Thus in GNU C the above example isequivalent to the following:@exampleint isroot (uid_t);intisroot (uid_t x)@{  return x == 0;@}@end exampleGNU C++ does not support old-style function definitions, so thisextension is irrelevant.@node C++ Comments@section C++ Style Comments@cindex //@cindex C++ comments@cindex comments, C++ styleIn GNU C, you may use C++ style comments, which start with @samp{//} andcontinue until the end of the line.  Many other C implementations allowsuch comments, and they are likely to be in a future C standard.However, C++ style comments are not recognized if you specify@w{@samp{-ansi}} or @w{@samp{-traditional}}, since they are incompatiblewith traditional constructs like @code{dividend//*comment*/divisor}.@node Dollar Signs@section Dollar Signs in Identifier Names@cindex $@cindex dollar signs in identifier names@cindex identifier names, dollar signs inIn GNU C, you may use dollar signs in identifier names.  This is becausemany traditional C implementations allow such identifiers.On some machines, dollar signs are allowed in identifiers if you specify@w{@samp{-traditional}}.  On a few systems they are allowed by default,even if you do not use @w{@samp{-traditional}}.  But they are neverallowed if you specify @w{@samp{-ansi}}.There are certain ANSI C programs (obscure, to be sure) that wouldcompile incorrectly if dollar signs were permitted in identifiers.  Forexample:@example#define foo(a) #a#define lose(b) foo (b)#define test$lose (test)@end example@node Character Escapes@section The Character @key{ESC} in ConstantsYou can use the sequence @samp{\e} in a string or character constant tostand for the ASCII character @key{ESC}.@node Alignment@section Inquiring on Alignment of Types or Variables@cindex alignment@cindex type alignment@cindex variable alignmentThe keyword @code{__alignof__} allows you to inquire about how an objectis aligned, or the minimum alignment usually required by a type.  Itssyntax is just like @code{sizeof}.For example, if the target machine requires a @code{double} value to bealigned on an 8-byte boundary, then @code{__alignof__ (double)} is 8.This is true on many RISC machines.  On more traditional machinedesigns, @code{__alignof__ (double)} is 4 or even 2.Some machines never actually require alignment; they allow reference to anydata type even at an odd addresses.  For these machines, @code{__alignof__}reports the @emph{recommended} alignment of a type.When the operand of @code{__alignof__} is an lvalue rather than a type, thevalue is the largest alignment that the lvalue is known to have.  It mayhave this alignment as a result of its data type, or because it is part ofa structure and inherits alignment from that structure.  For example, afterthis declaration:@examplestruct foo @{ int x; char y; @} foo1;@end example@noindentthe value of @code{__alignof__ (foo1.y)} is probably 2 or 4, the same as@code{__alignof__ (int)}, even though the data type of @code{foo1.y}does not itself demand any alignment.@refillA related feature which lets you specify the alignment of an object is@code{__attribute__ ((aligned (@var{alignment})))}; see the followingsection.@node Variable Attributes@section Specifying Attributes of Variables@cindex attribute of variables@cindex variable attributesThe keyword @code{__attribute__} allows you to specify specialattributes of variables or structure fields.  This keyword is followedby an attribute specification inside double parentheses.  Eightattributes are currently defined for variables: @code{aligned},@code{mode}, @code{nocommon}, @code{packed}, @code{section},@code{transparent_union}, @code{unused}, and @code{weak}.  Otherattributes are available for functions (@pxref{Function Attributes}) andfor types (@pxref{Type Attributes}).You may also specify attributes with @samp{__} preceding and followingeach keyword.  This allows you to use them in header files withoutbeing concerned about a possible macro of the same name.  For example,you may use @code{__aligned__} instead of @code{aligned}.@table @code@cindex @code{aligned} attribute@item aligned (@var{alignment})This attribute specifies a minimum alignment for the variable orstructure field, measured in bytes.  For example, the declaration:@smallexampleint x __attribute__ ((aligned (16))) = 0;@end smallexample@noindentcauses the compiler to allocate the global variable @code{x} on a16-byte boundary.  On a 68040, this could be used in conjunction withan @code{asm} expression to access the @code{move16} instruction whichrequires 16-byte aligned operands.You can also specify the alignment of structure fields.  For example, tocreate a double-word aligned @code{int} pair, you could write:@smallexamplestruct foo @{ int x[2] __attribute__ ((aligned (8))); @};@end smallexample@noindentThis is an alternative to creating a union with a @code{double} memberthat forces the union to be double-word aligned.It is not possible to specify the alignment of functions; the alignmentof functions is determined by the machine's requirements and cannot bechanged.  You cannot specify alignment for a typedef name because such aname is just an alias, not a distinct type.As in the preceding examples, you can explicitly specify the alignment(in bytes) that you wish the compiler to use for a given variable orstructure field.  Alternatively, you can leave out the alignment factorand just ask the compiler to align a variable or field to the maximumuseful alignment for the target machine you are compiling for.  Forexample, you could write:@smallexampleshort array[3] __attribute__ ((aligned));@end smallexampleWhenever you leave out the alignment factor in an @code{aligned} attributespecification, the compiler automatically sets the alignment for the declaredvariable or field to the largest alignment which is ever used for any datatype on the target machine you are compiling for.  Doing this can often makecopy operations more efficient, because the compiler can use whateverinstructions copy the biggest chunks of memory when performing copies toor from the variables or fields that you have aligned this way.The @code{aligned} attribute can only increase the alignment; but youcan decrease it by specifying @code{packed} as well.  See below.Note that the effectiveness of @code{aligned} attributes may be limitedby inherent limitations in your linker.  On many systems, the linker isonly able to arrange for variables to be aligned up to a certain maximumalignment.  (For some linkers, the maximum supported alignment maybe very very small.)  If your linker is only able to align variablesup to a maximum of 8 byte alignment, then specifying @code{aligned(16)}in an @code{__attribute__} will still only provide you with 8 bytealignment.  See your linker documentation for further information.@item mode (@var{mode})@cindex @code{mode} attributeThis attribute specifies the data type for the declaration---whichevertype corresponds to the mode @var{mode}.  This in effect lets yourequest an integer or floating point type according to its width.You may also specify a mode of @samp{byte} or @samp{__byte__} toindicate the mode corresponding to a one-byte integer, @samp{word} or@samp{__word__} for the mode of a one-word integer, and @samp{pointer}or @samp{__pointer__} for the mode used to represent pointers.@item nocommon@cindex @code{nocommon} attributeThis attribute specifies requests GNU CC not to place a variable``common'' but instead to allocate space for it directly.  If youspecify the @samp{-fno-common} flag, GNU CC will do this for allvariables.Specifying the @code{nocommon} attribute for a variable provides aninitialization of zeros.  A variable may only be initialized in onesource file.@item packed@cindex @code{packed} attributeThe @code{packed} attribute specifies that a variable or structure fieldshould have the smallest possible alignment---one byte for a variable,and one bit for a field, unless you specify a larger value with the@code{aligned} attribute.Here is a structure in which the field @code{x} is packed, so that itimmediately follows @code{a}:@examplestruct foo@{  char a;  int x[2] __attribute__ ((packed));@};@end example@item section ("section-name")@cindex @code{section} variable attributeNormally, the compiler places the objects it generates in sections like@code{data} and @code{bss}.  Sometimes, however, you need additional sections,or you need certain particular variables to appear in special sections,for example to map to special hardware.  The @code{section}attribute specifies that a variable (or function) lives in a particularsection.  For example, this small program uses several specific section names:@smallexamplestruct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @};struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @};char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @};int init_data_copy __attribute__ ((section ("INITDATACOPY"))) = 0;main()@{  /* Initialize stack pointer */  init_sp (stack + sizeof (stack));  /* Initialize initialized data */  memcpy (&init_data_copy, &data, &edata - &data);  /* Turn on the serial ports */  init_duart (&a);  init_duart (&b);@}@end smallexample@noindentUse the @code{section} attribute with an @emph{initialized} definitionof a @emph{global} variable, as shown in the example.  GNU CC issuesa warning and otherwise ignores the @code{section} attribute inuninitialized variable declarations.You may only use the @code{section} attribute with a fully initializedglobal definition because of the way linkers work.  The linker requireseach object be defined once, with the exception that uninitializedvariables tentatively go in the @code{common} (or @code{bss}) sectionand can be multiply "defined".  You can force a variable to beinitialized with the @samp{-fno-common} flag or the @code{nocommon}attribute.Some file formats do not support arbitrary sections so the @code{section}attribute is not available on all platforms.If you need to map the entire contents of a module to a particularsection, consider using the facilities of the linker instead.@item transparent_unionThis attribute, attached to a function argument variable which is aunion, means to pass the argument in the same way that the first unionmember would be passed.  You can also use this attribute on a@code{typedef} for a union data type; then it applies to all functionarguments with that type.@item unusedThis attribute, attached to a variable, means that the variable is meantto be 

⌨️ 快捷键说明

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