extend.texi revision 104752
1@c Copyright (C) 1988,1989,1992,1993,1994,1996,1998,1999,2000,2001,2002 Free Software Foundation, Inc. 2@c This is part of the GCC manual. 3@c For copying conditions, see the file gcc.texi. 4 5@node C Implementation 6@chapter C Implementation-defined behavior 7@cindex implementation-defined behavior, C language 8 9A conforming implementation of ISO C is required to document its 10choice of behavior in each of the areas that are designated 11``implementation defined.'' The following lists all such areas, 12along with the section number from the ISO/IEC 9899:1999 standard. 13 14@menu 15* Translation implementation:: 16* Environment implementation:: 17* Identifiers implementation:: 18* Characters implementation:: 19* Integers implementation:: 20* Floating point implementation:: 21* Arrays and pointers implementation:: 22* Hints implementation:: 23* Structures unions enumerations and bit-fields implementation:: 24* Qualifiers implementation:: 25* Preprocessing directives implementation:: 26* Library functions implementation:: 27* Architecture implementation:: 28* Locale-specific behavior implementation:: 29@end menu 30 31@node Translation implementation 32@section Translation 33 34@itemize @bullet 35@item 36@cite{How a diagnostic is identified (3.10, 5.1.1.3).} 37 38@item 39@cite{Whether each nonempty sequence of white-space characters other than 40new-line is retained or replaced by one space character in translation 41phase 3 (5.1.1.2).} 42@end itemize 43 44@node Environment implementation 45@section Environment 46 47The behavior of these points are dependent on the implementation 48of the C library, and are not defined by GCC itself. 49 50@node Identifiers implementation 51@section Identifiers 52 53@itemize @bullet 54@item 55@cite{Which additional multibyte characters may appear in identifiers 56and their correspondence to universal character names (6.4.2).} 57 58@item 59@cite{The number of significant initial characters in an identifier 60(5.2.4.1, 6.4.2).} 61@end itemize 62 63@node Characters implementation 64@section Characters 65 66@itemize @bullet 67@item 68@cite{The number of bits in a byte (3.6).} 69 70@item 71@cite{The values of the members of the execution character set (5.2.1).} 72 73@item 74@cite{The unique value of the member of the execution character set produced 75for each of the standard alphabetic escape sequences (5.2.2).} 76 77@item 78@cite{The value of a @code{char} object into which has been stored any 79character other than a member of the basic execution character set (6.2.5).} 80 81@item 82@cite{Which of @code{signed char} or @code{unsigned char} has the same range, 83representation, and behavior as ``plain'' @code{char} (6.2.5, 6.3.1.1).} 84 85@item 86@cite{The mapping of members of the source character set (in character 87constants and string literals) to members of the execution character 88set (6.4.4.4, 5.1.1.2).} 89 90@item 91@cite{The value of an integer character constant containing more than one 92character or containing a character or escape sequence that does not map 93to a single-byte execution character (6.4.4.4).} 94 95@item 96@cite{The value of a wide character constant containing more than one 97multibyte character, or containing a multibyte character or escape 98sequence not represented in the extended execution character set (6.4.4.4).} 99 100@item 101@cite{The current locale used to convert a wide character constant consisting 102of a single multibyte character that maps to a member of the extended 103execution character set into a corresponding wide character code (6.4.4.4).} 104 105@item 106@cite{The current locale used to convert a wide string literal into 107corresponding wide character codes (6.4.5).} 108 109@item 110@cite{The value of a string literal containing a multibyte character or escape 111sequence not represented in the execution character set (6.4.5).} 112@end itemize 113 114@node Integers implementation 115@section Integers 116 117@itemize @bullet 118@item 119@cite{Any extended integer types that exist in the implementation (6.2.5).} 120 121@item 122@cite{Whether signed integer types are represented using sign and magnitude, 123two's complement, or one's complement, and whether the extraordinary value 124is a trap representation or an ordinary value (6.2.6.2).} 125 126@item 127@cite{The rank of any extended integer type relative to another extended 128integer type with the same precision (6.3.1.1).} 129 130@item 131@cite{The result of, or the signal raised by, converting an integer to a 132signed integer type when the value cannot be represented in an object of 133that type (6.3.1.3).} 134 135@item 136@cite{The results of some bitwise operations on signed integers (6.5).} 137@end itemize 138 139@node Floating point implementation 140@section Floating point 141 142@itemize @bullet 143@item 144@cite{The accuracy of the floating-point operations and of the library 145functions in @code{<math.h>} and @code{<complex.h>} that return floating-point 146results (5.2.4.2.2).} 147 148@item 149@cite{The rounding behaviors characterized by non-standard values 150of @code{FLT_ROUNDS} @gol 151(5.2.4.2.2).} 152 153@item 154@cite{The evaluation methods characterized by non-standard negative 155values of @code{FLT_EVAL_METHOD} (5.2.4.2.2).} 156 157@item 158@cite{The direction of rounding when an integer is converted to a 159floating-point number that cannot exactly represent the original 160value (6.3.1.4).} 161 162@item 163@cite{The direction of rounding when a floating-point number is 164converted to a narrower floating-point number (6.3.1.5).} 165 166@item 167@cite{How the nearest representable value or the larger or smaller 168representable value immediately adjacent to the nearest representable 169value is chosen for certain floating constants (6.4.4.2).} 170 171@item 172@cite{Whether and how floating expressions are contracted when not 173disallowed by the @code{FP_CONTRACT} pragma (6.5).} 174 175@item 176@cite{The default state for the @code{FENV_ACCESS} pragma (7.6.1).} 177 178@item 179@cite{Additional floating-point exceptions, rounding modes, environments, 180and classifications, and their macro names (7.6, 7.12).} 181 182@item 183@cite{The default state for the @code{FP_CONTRACT} pragma (7.12.2).} 184 185@item 186@cite{Whether the ``inexact'' floating-point exception can be raised 187when the rounded result actually does equal the mathematical result 188in an IEC 60559 conformant implementation (F.9).} 189 190@item 191@cite{Whether the ``underflow'' (and ``inexact'') floating-point 192exception can be raised when a result is tiny but not inexact in an 193IEC 60559 conformant implementation (F.9).} 194 195@end itemize 196 197@node Arrays and pointers implementation 198@section Arrays and pointers 199 200@itemize @bullet 201@item 202@cite{The result of converting a pointer to an integer or 203vice versa (6.3.2.3).} 204 205A cast from pointer to integer discards most-significant bits if the 206pointer representation is larger than the integer type, 207sign-extends@footnote{Future versions of GCC may zero-extend, or use 208a target-defined @code{ptr_extend} pattern. Do not rely on sign extension.} 209if the pointer representation is smaller than the integer type, otherwise 210the bits are unchanged. 211@c ??? We've always claimed that pointers were unsigned entities. 212@c Shouldn't we therefore be doing zero-extension? If so, the bug 213@c is in convert_to_integer, where we call type_for_size and request 214@c a signed integral type. On the other hand, it might be most useful 215@c for the target if we extend according to POINTERS_EXTEND_UNSIGNED. 216 217A cast from integer to pointer discards most-significant bits if the 218pointer representation is smaller than the integer type, extends according 219to the signedness of the integer type if the pointer representation 220is larger than the integer type, otherwise the bits are unchanged. 221 222When casting from pointer to integer and back again, the resulting 223pointer must reference the same object as the original pointer, otherwise 224the behavior is undefined. That is, one may not use integer arithmetic to 225avoid the undefined behavior of pointer arithmetic as proscribed in 6.5.6/8. 226 227@item 228@cite{The size of the result of subtracting two pointers to elements 229of the same array (6.5.6).} 230 231@end itemize 232 233@node Hints implementation 234@section Hints 235 236@itemize @bullet 237@item 238@cite{The extent to which suggestions made by using the @code{register} 239storage-class specifier are effective (6.7.1).} 240 241@item 242@cite{The extent to which suggestions made by using the inline function 243specifier are effective (6.7.4).} 244 245@end itemize 246 247@node Structures unions enumerations and bit-fields implementation 248@section Structures, unions, enumerations, and bit-fields 249 250@itemize @bullet 251@item 252@cite{Whether a ``plain'' int bit-field is treated as a @code{signed int} 253bit-field or as an @code{unsigned int} bit-field (6.7.2, 6.7.2.1).} 254 255@item 256@cite{Allowable bit-field types other than @code{_Bool}, @code{signed int}, 257and @code{unsigned int} (6.7.2.1).} 258 259@item 260@cite{Whether a bit-field can straddle a storage-unit boundary (6.7.2.1).} 261 262@item 263@cite{The order of allocation of bit-fields within a unit (6.7.2.1).} 264 265@item 266@cite{The alignment of non-bit-field members of structures (6.7.2.1).} 267 268@item 269@cite{The integer type compatible with each enumerated type (6.7.2.2).} 270 271@end itemize 272 273@node Qualifiers implementation 274@section Qualifiers 275 276@itemize @bullet 277@item 278@cite{What constitutes an access to an object that has volatile-qualified 279type (6.7.3).} 280 281@end itemize 282 283@node Preprocessing directives implementation 284@section Preprocessing directives 285 286@itemize @bullet 287@item 288@cite{How sequences in both forms of header names are mapped to headers 289or external source file names (6.4.7).} 290 291@item 292@cite{Whether the value of a character constant in a constant expression 293that controls conditional inclusion matches the value of the same character 294constant in the execution character set (6.10.1).} 295 296@item 297@cite{Whether the value of a single-character character constant in a 298constant expression that controls conditional inclusion may have a 299negative value (6.10.1).} 300 301@item 302@cite{The places that are searched for an included @samp{<>} delimited 303header, and how the places are specified or the header is 304identified (6.10.2).} 305 306@item 307@cite{How the named source file is searched for in an included @samp{""} 308delimited header (6.10.2).} 309 310@item 311@cite{The method by which preprocessing tokens (possibly resulting from 312macro expansion) in a @code{#include} directive are combined into a header 313name (6.10.2).} 314 315@item 316@cite{The nesting limit for @code{#include} processing (6.10.2).} 317 318@item 319@cite{Whether the @samp{#} operator inserts a @samp{\} character before 320the @samp{\} character that begins a universal character name in a 321character constant or string literal (6.10.3.2).} 322 323@item 324@cite{The behavior on each recognized non-@code{STDC #pragma} 325directive (6.10.6).} 326 327@item 328@cite{The definitions for @code{__DATE__} and @code{__TIME__} when 329respectively, the date and time of translation are not available (6.10.8).} 330 331@end itemize 332 333@node Library functions implementation 334@section Library functions 335 336The behavior of these points are dependent on the implementation 337of the C library, and are not defined by GCC itself. 338 339@node Architecture implementation 340@section Architecture 341 342@itemize @bullet 343@item 344@cite{The values or expressions assigned to the macros specified in the 345headers @code{<float.h>}, @code{<limits.h>}, and @code{<stdint.h>} 346(5.2.4.2, 7.18.2, 7.18.3).} 347 348@item 349@cite{The number, order, and encoding of bytes in any object 350(when not explicitly specified in this International Standard) (6.2.6.1).} 351 352@item 353@cite{The value of the result of the sizeof operator (6.5.3.4).} 354 355@end itemize 356 357@node Locale-specific behavior implementation 358@section Locale-specific behavior 359 360The behavior of these points are dependent on the implementation 361of the C library, and are not defined by GCC itself. 362 363@node C Extensions 364@chapter Extensions to the C Language Family 365@cindex extensions, C language 366@cindex C language extensions 367 368@opindex pedantic 369GNU C provides several language features not found in ISO standard C@. 370(The @option{-pedantic} option directs GCC to print a warning message if 371any of these features is used.) To test for the availability of these 372features in conditional compilation, check for a predefined macro 373@code{__GNUC__}, which is always defined under GCC@. 374 375These extensions are available in C and Objective-C@. Most of them are 376also available in C++. @xref{C++ Extensions,,Extensions to the 377C++ Language}, for extensions that apply @emph{only} to C++. 378 379Some features that are in ISO C99 but not C89 or C++ are also, as 380extensions, accepted by GCC in C89 mode and in C++. 381 382@menu 383* Statement Exprs:: Putting statements and declarations inside expressions. 384* Local Labels:: Labels local to a statement-expression. 385* Labels as Values:: Getting pointers to labels, and computed gotos. 386* Nested Functions:: As in Algol and Pascal, lexical scoping of functions. 387* Constructing Calls:: Dispatching a call to another function. 388* Typeof:: @code{typeof}: referring to the type of an expression. 389* Lvalues:: Using @samp{?:}, @samp{,} and casts in lvalues. 390* Conditionals:: Omitting the middle operand of a @samp{?:} expression. 391* Long Long:: Double-word integers---@code{long long int}. 392* Complex:: Data types for complex numbers. 393* Hex Floats:: Hexadecimal floating-point constants. 394* Zero Length:: Zero-length arrays. 395* Variable Length:: Arrays whose length is computed at run time. 396* Variadic Macros:: Macros with a variable number of arguments. 397* Escaped Newlines:: Slightly looser rules for escaped newlines. 398* Multi-line Strings:: String literals with embedded newlines. 399* Subscripting:: Any array can be subscripted, even if not an lvalue. 400* Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers. 401* Initializers:: Non-constant initializers. 402* Compound Literals:: Compound literals give structures, unions 403 or arrays as values. 404* Designated Inits:: Labeling elements of initializers. 405* Cast to Union:: Casting to union type from any member of the union. 406* Case Ranges:: `case 1 ... 9' and such. 407* Mixed Declarations:: Mixing declarations and code. 408* Function Attributes:: Declaring that functions have no side effects, 409 or that they can never return. 410* Attribute Syntax:: Formal syntax for attributes. 411* Function Prototypes:: Prototype declarations and old-style definitions. 412* C++ Comments:: C++ comments are recognized. 413* Dollar Signs:: Dollar sign is allowed in identifiers. 414* Character Escapes:: @samp{\e} stands for the character @key{ESC}. 415* Variable Attributes:: Specifying attributes of variables. 416* Type Attributes:: Specifying attributes of types. 417* Alignment:: Inquiring about the alignment of a type or variable. 418* Inline:: Defining inline functions (as fast as macros). 419* Extended Asm:: Assembler instructions with C expressions as operands. 420 (With them you can define ``built-in'' functions.) 421* Constraints:: Constraints for asm operands 422* Asm Labels:: Specifying the assembler name to use for a C symbol. 423* Explicit Reg Vars:: Defining variables residing in specified registers. 424* Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files. 425* Incomplete Enums:: @code{enum foo;}, with details to follow. 426* Function Names:: Printable strings which are the name of the current 427 function. 428* Return Address:: Getting the return or frame address of a function. 429* Vector Extensions:: Using vector instructions through built-in functions. 430* Other Builtins:: Other built-in functions. 431* Target Builtins:: Built-in functions specific to particular targets. 432* Pragmas:: Pragmas accepted by GCC. 433* Unnamed Fields:: Unnamed struct/union fields within structs/unions. 434@end menu 435 436@node Statement Exprs 437@section Statements and Declarations in Expressions 438@cindex statements inside expressions 439@cindex declarations inside expressions 440@cindex expressions containing statements 441@cindex macros, statements in expressions 442 443@c the above section title wrapped and causes an underfull hbox.. i 444@c changed it from "within" to "in". --mew 4feb93 445 446A compound statement enclosed in parentheses may appear as an expression 447in GNU C@. This allows you to use loops, switches, and local variables 448within an expression. 449 450Recall that a compound statement is a sequence of statements surrounded 451by braces; in this construct, parentheses go around the braces. For 452example: 453 454@example 455(@{ int y = foo (); int z; 456 if (y > 0) z = y; 457 else z = - y; 458 z; @}) 459@end example 460 461@noindent 462is a valid (though slightly more complex than necessary) expression 463for the absolute value of @code{foo ()}. 464 465The last thing in the compound statement should be an expression 466followed by a semicolon; the value of this subexpression serves as the 467value of the entire construct. (If you use some other kind of statement 468last within the braces, the construct has type @code{void}, and thus 469effectively no value.) 470 471This feature is especially useful in making macro definitions ``safe'' (so 472that they evaluate each operand exactly once). For example, the 473``maximum'' function is commonly defined as a macro in standard C as 474follows: 475 476@example 477#define max(a,b) ((a) > (b) ? (a) : (b)) 478@end example 479 480@noindent 481@cindex side effects, macro argument 482But this definition computes either @var{a} or @var{b} twice, with bad 483results if the operand has side effects. In GNU C, if you know the 484type of the operands (here let's assume @code{int}), you can define 485the macro safely as follows: 486 487@example 488#define maxint(a,b) \ 489 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @}) 490@end example 491 492Embedded statements are not allowed in constant expressions, such as 493the value of an enumeration constant, the width of a bit-field, or 494the initial value of a static variable. 495 496If you don't know the type of the operand, you can still do this, but you 497must use @code{typeof} (@pxref{Typeof}). 498 499Statement expressions are not supported fully in G++, and their fate 500there is unclear. (It is possible that they will become fully supported 501at some point, or that they will be deprecated, or that the bugs that 502are present will continue to exist indefinitely.) Presently, statement 503expressions do not work well as default arguments. 504 505In addition, there are semantic issues with statement-expressions in 506C++. If you try to use statement-expressions instead of inline 507functions in C++, you may be surprised at the way object destruction is 508handled. For example: 509 510@example 511#define foo(a) (@{int b = (a); b + 3; @}) 512@end example 513 514@noindent 515does not work the same way as: 516 517@example 518inline int foo(int a) @{ int b = a; return b + 3; @} 519@end example 520 521@noindent 522In particular, if the expression passed into @code{foo} involves the 523creation of temporaries, the destructors for those temporaries will be 524run earlier in the case of the macro than in the case of the function. 525 526These considerations mean that it is probably a bad idea to use 527statement-expressions of this form in header files that are designed to 528work with C++. (Note that some versions of the GNU C Library contained 529header files using statement-expression that lead to precisely this 530bug.) 531 532@node Local Labels 533@section Locally Declared Labels 534@cindex local labels 535@cindex macros, local labels 536 537Each statement expression is a scope in which @dfn{local labels} can be 538declared. A local label is simply an identifier; you can jump to it 539with an ordinary @code{goto} statement, but only from within the 540statement expression it belongs to. 541 542A local label declaration looks like this: 543 544@example 545__label__ @var{label}; 546@end example 547 548@noindent 549or 550 551@example 552__label__ @var{label1}, @var{label2}, @dots{}; 553@end example 554 555Local label declarations must come at the beginning of the statement 556expression, right after the @samp{(@{}, before any ordinary 557declarations. 558 559The label declaration defines the label @emph{name}, but does not define 560the label itself. You must do this in the usual way, with 561@code{@var{label}:}, within the statements of the statement expression. 562 563The local label feature is useful because statement expressions are 564often used in macros. If the macro contains nested loops, a @code{goto} 565can be useful for breaking out of them. However, an ordinary label 566whose scope is the whole function cannot be used: if the macro can be 567expanded several times in one function, the label will be multiply 568defined in that function. A local label avoids this problem. For 569example: 570 571@example 572#define SEARCH(array, target) \ 573(@{ \ 574 __label__ found; \ 575 typeof (target) _SEARCH_target = (target); \ 576 typeof (*(array)) *_SEARCH_array = (array); \ 577 int i, j; \ 578 int value; \ 579 for (i = 0; i < max; i++) \ 580 for (j = 0; j < max; j++) \ 581 if (_SEARCH_array[i][j] == _SEARCH_target) \ 582 @{ value = i; goto found; @} \ 583 value = -1; \ 584 found: \ 585 value; \ 586@}) 587@end example 588 589@node Labels as Values 590@section Labels as Values 591@cindex labels as values 592@cindex computed gotos 593@cindex goto with computed label 594@cindex address of a label 595 596You can get the address of a label defined in the current function 597(or a containing function) with the unary operator @samp{&&}. The 598value has type @code{void *}. This value is a constant and can be used 599wherever a constant of that type is valid. For example: 600 601@example 602void *ptr; 603@dots{} 604ptr = &&foo; 605@end example 606 607To use these values, you need to be able to jump to one. This is done 608with the computed goto statement@footnote{The analogous feature in 609Fortran is called an assigned goto, but that name seems inappropriate in 610C, where one can do more than simply store label addresses in label 611variables.}, @code{goto *@var{exp};}. For example, 612 613@example 614goto *ptr; 615@end example 616 617@noindent 618Any expression of type @code{void *} is allowed. 619 620One way of using these constants is in initializing a static array that 621will serve as a jump table: 622 623@example 624static void *array[] = @{ &&foo, &&bar, &&hack @}; 625@end example 626 627Then you can select a label with indexing, like this: 628 629@example 630goto *array[i]; 631@end example 632 633@noindent 634Note that this does not check whether the subscript is in bounds---array 635indexing in C never does that. 636 637Such an array of label values serves a purpose much like that of the 638@code{switch} statement. The @code{switch} statement is cleaner, so 639use that rather than an array unless the problem does not fit a 640@code{switch} statement very well. 641 642Another use of label values is in an interpreter for threaded code. 643The labels within the interpreter function can be stored in the 644threaded code for super-fast dispatching. 645 646You may not use this mechanism to jump to code in a different function. 647If you do that, totally unpredictable things will happen. The best way to 648avoid this is to store the label address only in automatic variables and 649never pass it as an argument. 650 651An alternate way to write the above example is 652 653@example 654static const int array[] = @{ &&foo - &&foo, &&bar - &&foo, 655 &&hack - &&foo @}; 656goto *(&&foo + array[i]); 657@end example 658 659@noindent 660This is more friendly to code living in shared libraries, as it reduces 661the number of dynamic relocations that are needed, and by consequence, 662allows the data to be read-only. 663 664@node Nested Functions 665@section Nested Functions 666@cindex nested functions 667@cindex downward funargs 668@cindex thunks 669 670A @dfn{nested function} is a function defined inside another function. 671(Nested functions are not supported for GNU C++.) The nested function's 672name is local to the block where it is defined. For example, here we 673define a nested function named @code{square}, and call it twice: 674 675@example 676@group 677foo (double a, double b) 678@{ 679 double square (double z) @{ return z * z; @} 680 681 return square (a) + square (b); 682@} 683@end group 684@end example 685 686The nested function can access all the variables of the containing 687function that are visible at the point of its definition. This is 688called @dfn{lexical scoping}. For example, here we show a nested 689function which uses an inherited variable named @code{offset}: 690 691@example 692@group 693bar (int *array, int offset, int size) 694@{ 695 int access (int *array, int index) 696 @{ return array[index + offset]; @} 697 int i; 698 @dots{} 699 for (i = 0; i < size; i++) 700 @dots{} access (array, i) @dots{} 701@} 702@end group 703@end example 704 705Nested function definitions are permitted within functions in the places 706where variable definitions are allowed; that is, in any block, before 707the first statement in the block. 708 709It is possible to call the nested function from outside the scope of its 710name by storing its address or passing the address to another function: 711 712@example 713hack (int *array, int size) 714@{ 715 void store (int index, int value) 716 @{ array[index] = value; @} 717 718 intermediate (store, size); 719@} 720@end example 721 722Here, the function @code{intermediate} receives the address of 723@code{store} as an argument. If @code{intermediate} calls @code{store}, 724the arguments given to @code{store} are used to store into @code{array}. 725But this technique works only so long as the containing function 726(@code{hack}, in this example) does not exit. 727 728If you try to call the nested function through its address after the 729containing function has exited, all hell will break loose. If you try 730to call it after a containing scope level has exited, and if it refers 731to some of the variables that are no longer in scope, you may be lucky, 732but it's not wise to take the risk. If, however, the nested function 733does not refer to anything that has gone out of scope, you should be 734safe. 735 736GCC implements taking the address of a nested function using a technique 737called @dfn{trampolines}. A paper describing them is available as 738 739@noindent 740@uref{http://people.debian.org/~aaronl/Usenix88-lexic.pdf}. 741 742A nested function can jump to a label inherited from a containing 743function, provided the label was explicitly declared in the containing 744function (@pxref{Local Labels}). Such a jump returns instantly to the 745containing function, exiting the nested function which did the 746@code{goto} and any intermediate functions as well. Here is an example: 747 748@example 749@group 750bar (int *array, int offset, int size) 751@{ 752 __label__ failure; 753 int access (int *array, int index) 754 @{ 755 if (index > size) 756 goto failure; 757 return array[index + offset]; 758 @} 759 int i; 760 @dots{} 761 for (i = 0; i < size; i++) 762 @dots{} access (array, i) @dots{} 763 @dots{} 764 return 0; 765 766 /* @r{Control comes here from @code{access} 767 if it detects an error.} */ 768 failure: 769 return -1; 770@} 771@end group 772@end example 773 774A nested function always has internal linkage. Declaring one with 775@code{extern} is erroneous. If you need to declare the nested function 776before its definition, use @code{auto} (which is otherwise meaningless 777for function declarations). 778 779@example 780bar (int *array, int offset, int size) 781@{ 782 __label__ failure; 783 auto int access (int *, int); 784 @dots{} 785 int access (int *array, int index) 786 @{ 787 if (index > size) 788 goto failure; 789 return array[index + offset]; 790 @} 791 @dots{} 792@} 793@end example 794 795@node Constructing Calls 796@section Constructing Function Calls 797@cindex constructing calls 798@cindex forwarding calls 799 800Using the built-in functions described below, you can record 801the arguments a function received, and call another function 802with the same arguments, without knowing the number or types 803of the arguments. 804 805You can also record the return value of that function call, 806and later return that value, without knowing what data type 807the function tried to return (as long as your caller expects 808that data type). 809 810@deftypefn {Built-in Function} {void *} __builtin_apply_args () 811This built-in function returns a pointer to data 812describing how to perform a call with the same arguments as were passed 813to the current function. 814 815The function saves the arg pointer register, structure value address, 816and all registers that might be used to pass arguments to a function 817into a block of memory allocated on the stack. Then it returns the 818address of that block. 819@end deftypefn 820 821@deftypefn {Built-in Function} {void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size}) 822This built-in function invokes @var{function} 823with a copy of the parameters described by @var{arguments} 824and @var{size}. 825 826The value of @var{arguments} should be the value returned by 827@code{__builtin_apply_args}. The argument @var{size} specifies the size 828of the stack argument data, in bytes. 829 830This function returns a pointer to data describing 831how to return whatever value was returned by @var{function}. The data 832is saved in a block of memory allocated on the stack. 833 834It is not always simple to compute the proper value for @var{size}. The 835value is used by @code{__builtin_apply} to compute the amount of data 836that should be pushed on the stack and copied from the incoming argument 837area. 838@end deftypefn 839 840@deftypefn {Built-in Function} {void} __builtin_return (void *@var{result}) 841This built-in function returns the value described by @var{result} from 842the containing function. You should specify, for @var{result}, a value 843returned by @code{__builtin_apply}. 844@end deftypefn 845 846@cindex underscores in variables in macros 847@cindex @samp{_} in variables in macros 848@cindex local variables in macros 849@cindex variables, local, in macros 850@cindex macros, local variables in 851 852The reason for using names that start with underscores for the local 853variables is to avoid conflicts with variable names that occur within the 854expressions that are substituted for @code{a} and @code{b}. Eventually we 855hope to design a new form of declaration syntax that allows you to declare 856variables whose scopes start only after their initializers; this will be a 857more reliable way to prevent such conflicts. 858 859@node Typeof 860@section Referring to a Type with @code{typeof} 861@findex typeof 862@findex sizeof 863@cindex macros, types of arguments 864 865Another way to refer to the type of an expression is with @code{typeof}. 866The syntax of using of this keyword looks like @code{sizeof}, but the 867construct acts semantically like a type name defined with @code{typedef}. 868 869There are two ways of writing the argument to @code{typeof}: with an 870expression or with a type. Here is an example with an expression: 871 872@example 873typeof (x[0](1)) 874@end example 875 876@noindent 877This assumes that @code{x} is an array of pointers to functions; 878the type described is that of the values of the functions. 879 880Here is an example with a typename as the argument: 881 882@example 883typeof (int *) 884@end example 885 886@noindent 887Here the type described is that of pointers to @code{int}. 888 889If you are writing a header file that must work when included in ISO C 890programs, write @code{__typeof__} instead of @code{typeof}. 891@xref{Alternate Keywords}. 892 893A @code{typeof}-construct can be used anywhere a typedef name could be 894used. For example, you can use it in a declaration, in a cast, or inside 895of @code{sizeof} or @code{typeof}. 896 897@code{typeof} is often useful in conjunction with the 898statements-within-expressions feature. Here is how the two together can 899be used to define a safe ``maximum'' macro that operates on any 900arithmetic type and evaluates each of its arguments exactly once: 901 902@example 903#define max(a,b) \ 904 (@{ typeof (a) _a = (a); \ 905 typeof (b) _b = (b); \ 906 _a > _b ? _a : _b; @}) 907@end example 908 909@noindent 910Some more examples of the use of @code{typeof}: 911 912@itemize @bullet 913@item 914This declares @code{y} with the type of what @code{x} points to. 915 916@example 917typeof (*x) y; 918@end example 919 920@item 921This declares @code{y} as an array of such values. 922 923@example 924typeof (*x) y[4]; 925@end example 926 927@item 928This declares @code{y} as an array of pointers to characters: 929 930@example 931typeof (typeof (char *)[4]) y; 932@end example 933 934@noindent 935It is equivalent to the following traditional C declaration: 936 937@example 938char *y[4]; 939@end example 940 941To see the meaning of the declaration using @code{typeof}, and why it 942might be a useful way to write, let's rewrite it with these macros: 943 944@example 945#define pointer(T) typeof(T *) 946#define array(T, N) typeof(T [N]) 947@end example 948 949@noindent 950Now the declaration can be rewritten this way: 951 952@example 953array (pointer (char), 4) y; 954@end example 955 956@noindent 957Thus, @code{array (pointer (char), 4)} is the type of arrays of 4 958pointers to @code{char}. 959@end itemize 960 961@emph{Compatibility Note:} In addition to @code{typeof}, GCC 2 supported 962a more limited extension which permitted one to write 963 964@example 965typedef @var{T} = @var{expr}; 966@end example 967 968@noindent 969with the effect of declaring @var{T} to have the type of the expression 970@var{expr}. This extension does not work with GCC 3 (versions between 9713.0 and 3.2 will crash; 3.2.1 and later give an error). Code which 972relies on it should be rewritten to use @code{typeof}: 973 974@example 975typedef typeof(@var{expr}) @var{T}; 976@end example 977 978@noindent 979This will work with all versions of GCC@. 980 981@node Lvalues 982@section Generalized Lvalues 983@cindex compound expressions as lvalues 984@cindex expressions, compound, as lvalues 985@cindex conditional expressions as lvalues 986@cindex expressions, conditional, as lvalues 987@cindex casts as lvalues 988@cindex generalized lvalues 989@cindex lvalues, generalized 990@cindex extensions, @code{?:} 991@cindex @code{?:} extensions 992Compound expressions, conditional expressions and casts are allowed as 993lvalues provided their operands are lvalues. This means that you can take 994their addresses or store values into them. 995 996Standard C++ allows compound expressions and conditional expressions as 997lvalues, and permits casts to reference type, so use of this extension 998is deprecated for C++ code. 999 1000For example, a compound expression can be assigned, provided the last 1001expression in the sequence is an lvalue. These two expressions are 1002equivalent: 1003 1004@example 1005(a, b) += 5 1006a, (b += 5) 1007@end example 1008 1009Similarly, the address of the compound expression can be taken. These two 1010expressions are equivalent: 1011 1012@example 1013&(a, b) 1014a, &b 1015@end example 1016 1017A conditional expression is a valid lvalue if its type is not void and the 1018true and false branches are both valid lvalues. For example, these two 1019expressions are equivalent: 1020 1021@example 1022(a ? b : c) = 5 1023(a ? b = 5 : (c = 5)) 1024@end example 1025 1026A cast is a valid lvalue if its operand is an lvalue. A simple 1027assignment whose left-hand side is a cast works by converting the 1028right-hand side first to the specified type, then to the type of the 1029inner left-hand side expression. After this is stored, the value is 1030converted back to the specified type to become the value of the 1031assignment. Thus, if @code{a} has type @code{char *}, the following two 1032expressions are equivalent: 1033 1034@example 1035(int)a = 5 1036(int)(a = (char *)(int)5) 1037@end example 1038 1039An assignment-with-arithmetic operation such as @samp{+=} applied to a cast 1040performs the arithmetic using the type resulting from the cast, and then 1041continues as in the previous case. Therefore, these two expressions are 1042equivalent: 1043 1044@example 1045(int)a += 5 1046(int)(a = (char *)(int) ((int)a + 5)) 1047@end example 1048 1049You cannot take the address of an lvalue cast, because the use of its 1050address would not work out coherently. Suppose that @code{&(int)f} were 1051permitted, where @code{f} has type @code{float}. Then the following 1052statement would try to store an integer bit-pattern where a floating 1053point number belongs: 1054 1055@example 1056*&(int)f = 1; 1057@end example 1058 1059This is quite different from what @code{(int)f = 1} would do---that 1060would convert 1 to floating point and store it. Rather than cause this 1061inconsistency, we think it is better to prohibit use of @samp{&} on a cast. 1062 1063If you really do want an @code{int *} pointer with the address of 1064@code{f}, you can simply write @code{(int *)&f}. 1065 1066@node Conditionals 1067@section Conditionals with Omitted Operands 1068@cindex conditional expressions, extensions 1069@cindex omitted middle-operands 1070@cindex middle-operands, omitted 1071@cindex extensions, @code{?:} 1072@cindex @code{?:} extensions 1073 1074The middle operand in a conditional expression may be omitted. Then 1075if the first operand is nonzero, its value is the value of the conditional 1076expression. 1077 1078Therefore, the expression 1079 1080@example 1081x ? : y 1082@end example 1083 1084@noindent 1085has the value of @code{x} if that is nonzero; otherwise, the value of 1086@code{y}. 1087 1088This example is perfectly equivalent to 1089 1090@example 1091x ? x : y 1092@end example 1093 1094@cindex side effect in ?: 1095@cindex ?: side effect 1096@noindent 1097In this simple case, the ability to omit the middle operand is not 1098especially useful. When it becomes useful is when the first operand does, 1099or may (if it is a macro argument), contain a side effect. Then repeating 1100the operand in the middle would perform the side effect twice. Omitting 1101the middle operand uses the value already computed without the undesirable 1102effects of recomputing it. 1103 1104@node Long Long 1105@section Double-Word Integers 1106@cindex @code{long long} data types 1107@cindex double-word arithmetic 1108@cindex multiprecision arithmetic 1109@cindex @code{LL} integer suffix 1110@cindex @code{ULL} integer suffix 1111 1112ISO C99 supports data types for integers that are at least 64 bits wide, 1113and as an extension GCC supports them in C89 mode and in C++. 1114Simply write @code{long long int} for a signed integer, or 1115@code{unsigned long long int} for an unsigned integer. To make an 1116integer constant of type @code{long long int}, add the suffix @samp{LL} 1117to the integer. To make an integer constant of type @code{unsigned long 1118long int}, add the suffix @samp{ULL} to the integer. 1119 1120You can use these types in arithmetic like any other integer types. 1121Addition, subtraction, and bitwise boolean operations on these types 1122are open-coded on all types of machines. Multiplication is open-coded 1123if the machine supports fullword-to-doubleword a widening multiply 1124instruction. Division and shifts are open-coded only on machines that 1125provide special support. The operations that are not open-coded use 1126special library routines that come with GCC@. 1127 1128There may be pitfalls when you use @code{long long} types for function 1129arguments, unless you declare function prototypes. If a function 1130expects type @code{int} for its argument, and you pass a value of type 1131@code{long long int}, confusion will result because the caller and the 1132subroutine will disagree about the number of bytes for the argument. 1133Likewise, if the function expects @code{long long int} and you pass 1134@code{int}. The best way to avoid such problems is to use prototypes. 1135 1136@node Complex 1137@section Complex Numbers 1138@cindex complex numbers 1139@cindex @code{_Complex} keyword 1140@cindex @code{__complex__} keyword 1141 1142ISO C99 supports complex floating data types, and as an extension GCC 1143supports them in C89 mode and in C++, and supports complex integer data 1144types which are not part of ISO C99. You can declare complex types 1145using the keyword @code{_Complex}. As an extension, the older GNU 1146keyword @code{__complex__} is also supported. 1147 1148For example, @samp{_Complex double x;} declares @code{x} as a 1149variable whose real part and imaginary part are both of type 1150@code{double}. @samp{_Complex short int y;} declares @code{y} to 1151have real and imaginary parts of type @code{short int}; this is not 1152likely to be useful, but it shows that the set of complex types is 1153complete. 1154 1155To write a constant with a complex data type, use the suffix @samp{i} or 1156@samp{j} (either one; they are equivalent). For example, @code{2.5fi} 1157has type @code{_Complex float} and @code{3i} has type 1158@code{_Complex int}. Such a constant always has a pure imaginary 1159value, but you can form any complex value you like by adding one to a 1160real constant. This is a GNU extension; if you have an ISO C99 1161conforming C library (such as GNU libc), and want to construct complex 1162constants of floating type, you should include @code{<complex.h>} and 1163use the macros @code{I} or @code{_Complex_I} instead. 1164 1165@cindex @code{__real__} keyword 1166@cindex @code{__imag__} keyword 1167To extract the real part of a complex-valued expression @var{exp}, write 1168@code{__real__ @var{exp}}. Likewise, use @code{__imag__} to 1169extract the imaginary part. This is a GNU extension; for values of 1170floating type, you should use the ISO C99 functions @code{crealf}, 1171@code{creal}, @code{creall}, @code{cimagf}, @code{cimag} and 1172@code{cimagl}, declared in @code{<complex.h>} and also provided as 1173built-in functions by GCC@. 1174 1175@cindex complex conjugation 1176The operator @samp{~} performs complex conjugation when used on a value 1177with a complex type. This is a GNU extension; for values of 1178floating type, you should use the ISO C99 functions @code{conjf}, 1179@code{conj} and @code{conjl}, declared in @code{<complex.h>} and also 1180provided as built-in functions by GCC@. 1181 1182GCC can allocate complex automatic variables in a noncontiguous 1183fashion; it's even possible for the real part to be in a register while 1184the imaginary part is on the stack (or vice-versa). None of the 1185supported debugging info formats has a way to represent noncontiguous 1186allocation like this, so GCC describes a noncontiguous complex 1187variable as if it were two separate variables of noncomplex type. 1188If the variable's actual name is @code{foo}, the two fictitious 1189variables are named @code{foo$real} and @code{foo$imag}. You can 1190examine and set these two fictitious variables with your debugger. 1191 1192A future version of GDB will know how to recognize such pairs and treat 1193them as a single variable with a complex type. 1194 1195@node Hex Floats 1196@section Hex Floats 1197@cindex hex floats 1198 1199ISO C99 supports floating-point numbers written not only in the usual 1200decimal notation, such as @code{1.55e1}, but also numbers such as 1201@code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC 1202supports this in C89 mode (except in some cases when strictly 1203conforming) and in C++. In that format the 1204@samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are 1205mandatory. The exponent is a decimal number that indicates the power of 12062 by which the significant part will be multiplied. Thus @samp{0x1.f} is 1207@tex 1208$1 {15\over16}$, 1209@end tex 1210@ifnottex 12111 15/16, 1212@end ifnottex 1213@samp{p3} multiplies it by 8, and the value of @code{0x1.fp3} 1214is the same as @code{1.55e1}. 1215 1216Unlike for floating-point numbers in the decimal notation the exponent 1217is always required in the hexadecimal notation. Otherwise the compiler 1218would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This 1219could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the 1220extension for floating-point constants of type @code{float}. 1221 1222@node Zero Length 1223@section Arrays of Length Zero 1224@cindex arrays of length zero 1225@cindex zero-length arrays 1226@cindex length-zero arrays 1227@cindex flexible array members 1228 1229Zero-length arrays are allowed in GNU C@. They are very useful as the 1230last element of a structure which is really a header for a variable-length 1231object: 1232 1233@example 1234struct line @{ 1235 int length; 1236 char contents[0]; 1237@}; 1238 1239struct line *thisline = (struct line *) 1240 malloc (sizeof (struct line) + this_length); 1241thisline->length = this_length; 1242@end example 1243 1244In ISO C89, you would have to give @code{contents} a length of 1, which 1245means either you waste space or complicate the argument to @code{malloc}. 1246 1247In ISO C99, you would use a @dfn{flexible array member}, which is 1248slightly different in syntax and semantics: 1249 1250@itemize @bullet 1251@item 1252Flexible array members are written as @code{contents[]} without 1253the @code{0}. 1254 1255@item 1256Flexible array members have incomplete type, and so the @code{sizeof} 1257operator may not be applied. As a quirk of the original implementation 1258of zero-length arrays, @code{sizeof} evaluates to zero. 1259 1260@item 1261Flexible array members may only appear as the last member of a 1262@code{struct} that is otherwise non-empty. 1263@end itemize 1264 1265GCC versions before 3.0 allowed zero-length arrays to be statically 1266initialized, as if they were flexible arrays. In addition to those 1267cases that were useful, it also allowed initializations in situations 1268that would corrupt later data. Non-empty initialization of zero-length 1269arrays is now treated like any case where there are more initializer 1270elements than the array holds, in that a suitable warning about "excess 1271elements in array" is given, and the excess elements (all of them, in 1272this case) are ignored. 1273 1274Instead GCC allows static initialization of flexible array members. 1275This is equivalent to defining a new structure containing the original 1276structure followed by an array of sufficient size to contain the data. 1277I.e.@: in the following, @code{f1} is constructed as if it were declared 1278like @code{f2}. 1279 1280@example 1281struct f1 @{ 1282 int x; int y[]; 1283@} f1 = @{ 1, @{ 2, 3, 4 @} @}; 1284 1285struct f2 @{ 1286 struct f1 f1; int data[3]; 1287@} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @}; 1288@end example 1289 1290@noindent 1291The convenience of this extension is that @code{f1} has the desired 1292type, eliminating the need to consistently refer to @code{f2.f1}. 1293 1294This has symmetry with normal static arrays, in that an array of 1295unknown size is also written with @code{[]}. 1296 1297Of course, this extension only makes sense if the extra data comes at 1298the end of a top-level object, as otherwise we would be overwriting 1299data at subsequent offsets. To avoid undue complication and confusion 1300with initialization of deeply nested arrays, we simply disallow any 1301non-empty initialization except when the structure is the top-level 1302object. For example: 1303 1304@example 1305struct foo @{ int x; int y[]; @}; 1306struct bar @{ struct foo z; @}; 1307 1308struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.} 1309struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.} 1310struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.} 1311struct foo d[1] = @{ @{ 1 @{ 2, 3, 4 @} @} @}; // @r{Invalid.} 1312@end example 1313 1314@node Variable Length 1315@section Arrays of Variable Length 1316@cindex variable-length arrays 1317@cindex arrays of variable length 1318@cindex VLAs 1319 1320Variable-length automatic arrays are allowed in ISO C99, and as an 1321extension GCC accepts them in C89 mode and in C++. (However, GCC's 1322implementation of variable-length arrays does not yet conform in detail 1323to the ISO C99 standard.) These arrays are 1324declared like any other automatic arrays, but with a length that is not 1325a constant expression. The storage is allocated at the point of 1326declaration and deallocated when the brace-level is exited. For 1327example: 1328 1329@example 1330FILE * 1331concat_fopen (char *s1, char *s2, char *mode) 1332@{ 1333 char str[strlen (s1) + strlen (s2) + 1]; 1334 strcpy (str, s1); 1335 strcat (str, s2); 1336 return fopen (str, mode); 1337@} 1338@end example 1339 1340@cindex scope of a variable length array 1341@cindex variable-length array scope 1342@cindex deallocating variable length arrays 1343Jumping or breaking out of the scope of the array name deallocates the 1344storage. Jumping into the scope is not allowed; you get an error 1345message for it. 1346 1347@cindex @code{alloca} vs variable-length arrays 1348You can use the function @code{alloca} to get an effect much like 1349variable-length arrays. The function @code{alloca} is available in 1350many other C implementations (but not in all). On the other hand, 1351variable-length arrays are more elegant. 1352 1353There are other differences between these two methods. Space allocated 1354with @code{alloca} exists until the containing @emph{function} returns. 1355The space for a variable-length array is deallocated as soon as the array 1356name's scope ends. (If you use both variable-length arrays and 1357@code{alloca} in the same function, deallocation of a variable-length array 1358will also deallocate anything more recently allocated with @code{alloca}.) 1359 1360You can also use variable-length arrays as arguments to functions: 1361 1362@example 1363struct entry 1364tester (int len, char data[len][len]) 1365@{ 1366 @dots{} 1367@} 1368@end example 1369 1370The length of an array is computed once when the storage is allocated 1371and is remembered for the scope of the array in case you access it with 1372@code{sizeof}. 1373 1374If you want to pass the array first and the length afterward, you can 1375use a forward declaration in the parameter list---another GNU extension. 1376 1377@example 1378struct entry 1379tester (int len; char data[len][len], int len) 1380@{ 1381 @dots{} 1382@} 1383@end example 1384 1385@cindex parameter forward declaration 1386The @samp{int len} before the semicolon is a @dfn{parameter forward 1387declaration}, and it serves the purpose of making the name @code{len} 1388known when the declaration of @code{data} is parsed. 1389 1390You can write any number of such parameter forward declarations in the 1391parameter list. They can be separated by commas or semicolons, but the 1392last one must end with a semicolon, which is followed by the ``real'' 1393parameter declarations. Each forward declaration must match a ``real'' 1394declaration in parameter name and data type. ISO C99 does not support 1395parameter forward declarations. 1396 1397@node Variadic Macros 1398@section Macros with a Variable Number of Arguments. 1399@cindex variable number of arguments 1400@cindex macro with variable arguments 1401@cindex rest argument (in macro) 1402@cindex variadic macros 1403 1404In the ISO C standard of 1999, a macro can be declared to accept a 1405variable number of arguments much as a function can. The syntax for 1406defining the macro is similar to that of a function. Here is an 1407example: 1408 1409@smallexample 1410#define debug(format, ...) fprintf (stderr, format, __VA_ARGS__) 1411@end smallexample 1412 1413Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of 1414such a macro, it represents the zero or more tokens until the closing 1415parenthesis that ends the invocation, including any commas. This set of 1416tokens replaces the identifier @code{__VA_ARGS__} in the macro body 1417wherever it appears. See the CPP manual for more information. 1418 1419GCC has long supported variadic macros, and used a different syntax that 1420allowed you to give a name to the variable arguments just like any other 1421argument. Here is an example: 1422 1423@example 1424#define debug(format, args...) fprintf (stderr, format, args) 1425@end example 1426 1427This is in all ways equivalent to the ISO C example above, but arguably 1428more readable and descriptive. 1429 1430GNU CPP has two further variadic macro extensions, and permits them to 1431be used with either of the above forms of macro definition. 1432 1433In standard C, you are not allowed to leave the variable argument out 1434entirely; but you are allowed to pass an empty argument. For example, 1435this invocation is invalid in ISO C, because there is no comma after 1436the string: 1437 1438@example 1439debug ("A message") 1440@end example 1441 1442GNU CPP permits you to completely omit the variable arguments in this 1443way. In the above examples, the compiler would complain, though since 1444the expansion of the macro still has the extra comma after the format 1445string. 1446 1447To help solve this problem, CPP behaves specially for variable arguments 1448used with the token paste operator, @samp{##}. If instead you write 1449 1450@smallexample 1451#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__) 1452@end smallexample 1453 1454and if the variable arguments are omitted or empty, the @samp{##} 1455operator causes the preprocessor to remove the comma before it. If you 1456do provide some variable arguments in your macro invocation, GNU CPP 1457does not complain about the paste operation and instead places the 1458variable arguments after the comma. Just like any other pasted macro 1459argument, these arguments are not macro expanded. 1460 1461@node Escaped Newlines 1462@section Slightly Looser Rules for Escaped Newlines 1463@cindex escaped newlines 1464@cindex newlines (escaped) 1465 1466Recently, the non-traditional preprocessor has relaxed its treatment of 1467escaped newlines. Previously, the newline had to immediately follow a 1468backslash. The current implementation allows whitespace in the form of 1469spaces, horizontal and vertical tabs, and form feeds between the 1470backslash and the subsequent newline. The preprocessor issues a 1471warning, but treats it as a valid escaped newline and combines the two 1472lines to form a single logical line. This works within comments and 1473tokens, including multi-line strings, as well as between tokens. 1474Comments are @emph{not} treated as whitespace for the purposes of this 1475relaxation, since they have not yet been replaced with spaces. 1476 1477@node Multi-line Strings 1478@section String Literals with Embedded Newlines 1479@cindex multi-line string literals 1480 1481As an extension, GNU CPP permits string literals to cross multiple lines 1482without escaping the embedded newlines. Each embedded newline is 1483replaced with a single @samp{\n} character in the resulting string 1484literal, regardless of what form the newline took originally. 1485 1486CPP currently allows such strings in directives as well (other than the 1487@samp{#include} family). This is deprecated and will eventually be 1488removed. 1489 1490@node Subscripting 1491@section Non-Lvalue Arrays May Have Subscripts 1492@cindex subscripting 1493@cindex arrays, non-lvalue 1494 1495@cindex subscripting and function values 1496In ISO C99, arrays that are not lvalues still decay to pointers, and 1497may be subscripted, although they may not be modified or used after 1498the next sequence point and the unary @samp{&} operator may not be 1499applied to them. As an extension, GCC allows such arrays to be 1500subscripted in C89 mode, though otherwise they do not decay to 1501pointers outside C99 mode. For example, 1502this is valid in GNU C though not valid in C89: 1503 1504@example 1505@group 1506struct foo @{int a[4];@}; 1507 1508struct foo f(); 1509 1510bar (int index) 1511@{ 1512 return f().a[index]; 1513@} 1514@end group 1515@end example 1516 1517@node Pointer Arith 1518@section Arithmetic on @code{void}- and Function-Pointers 1519@cindex void pointers, arithmetic 1520@cindex void, size of pointer to 1521@cindex function pointers, arithmetic 1522@cindex function, size of pointer to 1523 1524In GNU C, addition and subtraction operations are supported on pointers to 1525@code{void} and on pointers to functions. This is done by treating the 1526size of a @code{void} or of a function as 1. 1527 1528A consequence of this is that @code{sizeof} is also allowed on @code{void} 1529and on function types, and returns 1. 1530 1531@opindex Wpointer-arith 1532The option @option{-Wpointer-arith} requests a warning if these extensions 1533are used. 1534 1535@node Initializers 1536@section Non-Constant Initializers 1537@cindex initializers, non-constant 1538@cindex non-constant initializers 1539 1540As in standard C++ and ISO C99, the elements of an aggregate initializer for an 1541automatic variable are not required to be constant expressions in GNU C@. 1542Here is an example of an initializer with run-time varying elements: 1543 1544@example 1545foo (float f, float g) 1546@{ 1547 float beat_freqs[2] = @{ f-g, f+g @}; 1548 @dots{} 1549@} 1550@end example 1551 1552@node Compound Literals 1553@section Compound Literals 1554@cindex constructor expressions 1555@cindex initializations in expressions 1556@cindex structures, constructor expression 1557@cindex expressions, constructor 1558@cindex compound literals 1559@c The GNU C name for what C99 calls compound literals was "constructor expressions". 1560 1561ISO C99 supports compound literals. A compound literal looks like 1562a cast containing an initializer. Its value is an object of the 1563type specified in the cast, containing the elements specified in 1564the initializer; it is an lvalue. As an extension, GCC supports 1565compound literals in C89 mode and in C++. 1566 1567Usually, the specified type is a structure. Assume that 1568@code{struct foo} and @code{structure} are declared as shown: 1569 1570@example 1571struct foo @{int a; char b[2];@} structure; 1572@end example 1573 1574@noindent 1575Here is an example of constructing a @code{struct foo} with a compound literal: 1576 1577@example 1578structure = ((struct foo) @{x + y, 'a', 0@}); 1579@end example 1580 1581@noindent 1582This is equivalent to writing the following: 1583 1584@example 1585@{ 1586 struct foo temp = @{x + y, 'a', 0@}; 1587 structure = temp; 1588@} 1589@end example 1590 1591You can also construct an array. If all the elements of the compound literal 1592are (made up of) simple constant expressions, suitable for use in 1593initializers of objects of static storage duration, then the compound 1594literal can be coerced to a pointer to its first element and used in 1595such an initializer, as shown here: 1596 1597@example 1598char **foo = (char *[]) @{ "x", "y", "z" @}; 1599@end example 1600 1601Compound literals for scalar types and union types are is 1602also allowed, but then the compound literal is equivalent 1603to a cast. 1604 1605As a GNU extension, GCC allows initialization of objects with static storage 1606duration by compound literals (which is not possible in ISO C99, because 1607the initializer is not a constant). 1608It is handled as if the object was initialized only with the bracket 1609enclosed list if compound literal's and object types match. 1610The initializer list of the compound literal must be constant. 1611If the object being initialized has array type of unknown size, the size is 1612determined by compound literal size. 1613 1614@example 1615static struct foo x = (struct foo) @{1, 'a', 'b'@}; 1616static int y[] = (int []) @{1, 2, 3@}; 1617static int z[] = (int [3]) @{1@}; 1618@end example 1619 1620@noindent 1621The above lines are equivalent to the following: 1622@example 1623static struct foo x = @{1, 'a', 'b'@}; 1624static int y[] = @{1, 2, 3@}; 1625static int z[] = @{1, 0, 0@}; 1626@end example 1627 1628@node Designated Inits 1629@section Designated Initializers 1630@cindex initializers with labeled elements 1631@cindex labeled elements in initializers 1632@cindex case labels in initializers 1633@cindex designated initializers 1634 1635Standard C89 requires the elements of an initializer to appear in a fixed 1636order, the same as the order of the elements in the array or structure 1637being initialized. 1638 1639In ISO C99 you can give the elements in any order, specifying the array 1640indices or structure field names they apply to, and GNU C allows this as 1641an extension in C89 mode as well. This extension is not 1642implemented in GNU C++. 1643 1644To specify an array index, write 1645@samp{[@var{index}] =} before the element value. For example, 1646 1647@example 1648int a[6] = @{ [4] = 29, [2] = 15 @}; 1649@end example 1650 1651@noindent 1652is equivalent to 1653 1654@example 1655int a[6] = @{ 0, 0, 15, 0, 29, 0 @}; 1656@end example 1657 1658@noindent 1659The index values must be constant expressions, even if the array being 1660initialized is automatic. 1661 1662An alternative syntax for this which has been obsolete since GCC 2.5 but 1663GCC still accepts is to write @samp{[@var{index}]} before the element 1664value, with no @samp{=}. 1665 1666To initialize a range of elements to the same value, write 1667@samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU 1668extension. For example, 1669 1670@example 1671int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @}; 1672@end example 1673 1674@noindent 1675If the value in it has side-effects, the side-effects will happen only once, 1676not for each initialized field by the range initializer. 1677 1678@noindent 1679Note that the length of the array is the highest value specified 1680plus one. 1681 1682In a structure initializer, specify the name of a field to initialize 1683with @samp{.@var{fieldname} =} before the element value. For example, 1684given the following structure, 1685 1686@example 1687struct point @{ int x, y; @}; 1688@end example 1689 1690@noindent 1691the following initialization 1692 1693@example 1694struct point p = @{ .y = yvalue, .x = xvalue @}; 1695@end example 1696 1697@noindent 1698is equivalent to 1699 1700@example 1701struct point p = @{ xvalue, yvalue @}; 1702@end example 1703 1704Another syntax which has the same meaning, obsolete since GCC 2.5, is 1705@samp{@var{fieldname}:}, as shown here: 1706 1707@example 1708struct point p = @{ y: yvalue, x: xvalue @}; 1709@end example 1710 1711@cindex designators 1712The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a 1713@dfn{designator}. You can also use a designator (or the obsolete colon 1714syntax) when initializing a union, to specify which element of the union 1715should be used. For example, 1716 1717@example 1718union foo @{ int i; double d; @}; 1719 1720union foo f = @{ .d = 4 @}; 1721@end example 1722 1723@noindent 1724will convert 4 to a @code{double} to store it in the union using 1725the second element. By contrast, casting 4 to type @code{union foo} 1726would store it into the union as the integer @code{i}, since it is 1727an integer. (@xref{Cast to Union}.) 1728 1729You can combine this technique of naming elements with ordinary C 1730initialization of successive elements. Each initializer element that 1731does not have a designator applies to the next consecutive element of the 1732array or structure. For example, 1733 1734@example 1735int a[6] = @{ [1] = v1, v2, [4] = v4 @}; 1736@end example 1737 1738@noindent 1739is equivalent to 1740 1741@example 1742int a[6] = @{ 0, v1, v2, 0, v4, 0 @}; 1743@end example 1744 1745Labeling the elements of an array initializer is especially useful 1746when the indices are characters or belong to an @code{enum} type. 1747For example: 1748 1749@example 1750int whitespace[256] 1751 = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1, 1752 ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @}; 1753@end example 1754 1755@cindex designator lists 1756You can also write a series of @samp{.@var{fieldname}} and 1757@samp{[@var{index}]} designators before an @samp{=} to specify a 1758nested subobject to initialize; the list is taken relative to the 1759subobject corresponding to the closest surrounding brace pair. For 1760example, with the @samp{struct point} declaration above: 1761 1762@smallexample 1763struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @}; 1764@end smallexample 1765 1766@noindent 1767If the same field is initialized multiple times, it will have value from 1768the last initialization. If any such overridden initialization has 1769side-effect, it is unspecified whether the side-effect happens or not. 1770Currently, gcc will discard them and issue a warning. 1771 1772@node Case Ranges 1773@section Case Ranges 1774@cindex case ranges 1775@cindex ranges in case statements 1776 1777You can specify a range of consecutive values in a single @code{case} label, 1778like this: 1779 1780@example 1781case @var{low} ... @var{high}: 1782@end example 1783 1784@noindent 1785This has the same effect as the proper number of individual @code{case} 1786labels, one for each integer value from @var{low} to @var{high}, inclusive. 1787 1788This feature is especially useful for ranges of ASCII character codes: 1789 1790@example 1791case 'A' ... 'Z': 1792@end example 1793 1794@strong{Be careful:} Write spaces around the @code{...}, for otherwise 1795it may be parsed wrong when you use it with integer values. For example, 1796write this: 1797 1798@example 1799case 1 ... 5: 1800@end example 1801 1802@noindent 1803rather than this: 1804 1805@example 1806case 1...5: 1807@end example 1808 1809@node Cast to Union 1810@section Cast to a Union Type 1811@cindex cast to a union 1812@cindex union, casting to a 1813 1814A cast to union type is similar to other casts, except that the type 1815specified is a union type. You can specify the type either with 1816@code{union @var{tag}} or with a typedef name. A cast to union is actually 1817a constructor though, not a cast, and hence does not yield an lvalue like 1818normal casts. (@xref{Compound Literals}.) 1819 1820The types that may be cast to the union type are those of the members 1821of the union. Thus, given the following union and variables: 1822 1823@example 1824union foo @{ int i; double d; @}; 1825int x; 1826double y; 1827@end example 1828 1829@noindent 1830both @code{x} and @code{y} can be cast to type @code{union foo}. 1831 1832Using the cast as the right-hand side of an assignment to a variable of 1833union type is equivalent to storing in a member of the union: 1834 1835@example 1836union foo u; 1837@dots{} 1838u = (union foo) x @equiv{} u.i = x 1839u = (union foo) y @equiv{} u.d = y 1840@end example 1841 1842You can also use the union cast as a function argument: 1843 1844@example 1845void hack (union foo); 1846@dots{} 1847hack ((union foo) x); 1848@end example 1849 1850@node Mixed Declarations 1851@section Mixed Declarations and Code 1852@cindex mixed declarations and code 1853@cindex declarations, mixed with code 1854@cindex code, mixed with declarations 1855 1856ISO C99 and ISO C++ allow declarations and code to be freely mixed 1857within compound statements. As an extension, GCC also allows this in 1858C89 mode. For example, you could do: 1859 1860@example 1861int i; 1862@dots{} 1863i++; 1864int j = i + 2; 1865@end example 1866 1867Each identifier is visible from where it is declared until the end of 1868the enclosing block. 1869 1870@node Function Attributes 1871@section Declaring Attributes of Functions 1872@cindex function attributes 1873@cindex declaring attributes of functions 1874@cindex functions that never return 1875@cindex functions that have no side effects 1876@cindex functions in arbitrary sections 1877@cindex functions that behave like malloc 1878@cindex @code{volatile} applied to function 1879@cindex @code{const} applied to function 1880@cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments 1881@cindex functions that are passed arguments in registers on the 386 1882@cindex functions that pop the argument stack on the 386 1883@cindex functions that do not pop the argument stack on the 386 1884 1885In GNU C, you declare certain things about functions called in your program 1886which help the compiler optimize function calls and check your code more 1887carefully. 1888 1889The keyword @code{__attribute__} allows you to specify special 1890attributes when making a declaration. This keyword is followed by an 1891attribute specification inside double parentheses. The following 1892attributes are currently defined for functions on all targets: 1893@code{noreturn}, @code{noinline}, @code{always_inline}, 1894@code{pure}, @code{const}, 1895@code{format}, @code{format_arg}, @code{no_instrument_function}, 1896@code{section}, @code{constructor}, @code{destructor}, @code{used}, 1897@code{unused}, @code{deprecated}, @code{weak}, @code{malloc}, and 1898@code{alias}. Several other attributes are defined for functions on 1899particular target systems. Other attributes, including @code{section} 1900are supported for variables declarations (@pxref{Variable Attributes}) 1901and for types (@pxref{Type Attributes}). 1902 1903You may also specify attributes with @samp{__} preceding and following 1904each keyword. This allows you to use them in header files without 1905being concerned about a possible macro of the same name. For example, 1906you may use @code{__noreturn__} instead of @code{noreturn}. 1907 1908@xref{Attribute Syntax}, for details of the exact syntax for using 1909attributes. 1910 1911@table @code 1912@cindex @code{noreturn} function attribute 1913@item noreturn 1914A few standard library functions, such as @code{abort} and @code{exit}, 1915cannot return. GCC knows this automatically. Some programs define 1916their own functions that never return. You can declare them 1917@code{noreturn} to tell the compiler this fact. For example, 1918 1919@smallexample 1920@group 1921void fatal () __attribute__ ((noreturn)); 1922 1923void 1924fatal (@dots{}) 1925@{ 1926 @dots{} /* @r{Print error message.} */ @dots{} 1927 exit (1); 1928@} 1929@end group 1930@end smallexample 1931 1932The @code{noreturn} keyword tells the compiler to assume that 1933@code{fatal} cannot return. It can then optimize without regard to what 1934would happen if @code{fatal} ever did return. This makes slightly 1935better code. More importantly, it helps avoid spurious warnings of 1936uninitialized variables. 1937 1938Do not assume that registers saved by the calling function are 1939restored before calling the @code{noreturn} function. 1940 1941It does not make sense for a @code{noreturn} function to have a return 1942type other than @code{void}. 1943 1944The attribute @code{noreturn} is not implemented in GCC versions 1945earlier than 2.5. An alternative way to declare that a function does 1946not return, which works in the current version and in some older 1947versions, is as follows: 1948 1949@smallexample 1950typedef void voidfn (); 1951 1952volatile voidfn fatal; 1953@end smallexample 1954 1955@cindex @code{noinline} function attribute 1956@item noinline 1957This function attribute prevents a function from being considered for 1958inlining. 1959 1960@cindex @code{always_inline} function attribute 1961@item always_inline 1962Generally, functions are not inlined unless optimization is specified. 1963For functions declared inline, this attribute inlines the function even 1964if no optimization level was specified. 1965 1966@cindex @code{pure} function attribute 1967@item pure 1968Many functions have no effects except the return value and their 1969return value depends only on the parameters and/or global variables. 1970Such a function can be subject 1971to common subexpression elimination and loop optimization just as an 1972arithmetic operator would be. These functions should be declared 1973with the attribute @code{pure}. For example, 1974 1975@smallexample 1976int square (int) __attribute__ ((pure)); 1977@end smallexample 1978 1979@noindent 1980says that the hypothetical function @code{square} is safe to call 1981fewer times than the program says. 1982 1983Some of common examples of pure functions are @code{strlen} or @code{memcmp}. 1984Interesting non-pure functions are functions with infinite loops or those 1985depending on volatile memory or other system resource, that may change between 1986two consecutive calls (such as @code{feof} in a multithreading environment). 1987 1988The attribute @code{pure} is not implemented in GCC versions earlier 1989than 2.96. 1990@cindex @code{const} function attribute 1991@item const 1992Many functions do not examine any values except their arguments, and 1993have no effects except the return value. Basically this is just slightly 1994more strict class than the @code{pure} attribute above, since function is not 1995allowed to read global memory. 1996 1997@cindex pointer arguments 1998Note that a function that has pointer arguments and examines the data 1999pointed to must @emph{not} be declared @code{const}. Likewise, a 2000function that calls a non-@code{const} function usually must not be 2001@code{const}. It does not make sense for a @code{const} function to 2002return @code{void}. 2003 2004The attribute @code{const} is not implemented in GCC versions earlier 2005than 2.5. An alternative way to declare that a function has no side 2006effects, which works in the current version and in some older versions, 2007is as follows: 2008 2009@smallexample 2010typedef int intfn (); 2011 2012extern const intfn square; 2013@end smallexample 2014 2015This approach does not work in GNU C++ from 2.6.0 on, since the language 2016specifies that the @samp{const} must be attached to the return value. 2017 2018 2019@item format (@var{archetype}, @var{string-index}, @var{first-to-check}) 2020@cindex @code{format} function attribute 2021@opindex Wformat 2022The @code{format} attribute specifies that a function takes @code{printf}, 2023@code{scanf}, @code{strftime} or @code{strfmon} style arguments which 2024should be type-checked against a format string. For example, the 2025declaration: 2026 2027@smallexample 2028extern int 2029my_printf (void *my_object, const char *my_format, ...) 2030 __attribute__ ((format (printf, 2, 3))); 2031@end smallexample 2032 2033@noindent 2034causes the compiler to check the arguments in calls to @code{my_printf} 2035for consistency with the @code{printf} style format string argument 2036@code{my_format}. 2037 2038The parameter @var{archetype} determines how the format string is 2039interpreted, and should be @code{printf}, @code{scanf}, @code{strftime} 2040or @code{strfmon}. (You can also use @code{__printf__}, 2041@code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) The 2042parameter @var{string-index} specifies which argument is the format 2043string argument (starting from 1), while @var{first-to-check} is the 2044number of the first argument to check against the format string. For 2045functions where the arguments are not available to be checked (such as 2046@code{vprintf}), specify the third parameter as zero. In this case the 2047compiler only checks the format string for consistency. For 2048@code{strftime} formats, the third parameter is required to be zero. 2049 2050In the example above, the format string (@code{my_format}) is the second 2051argument of the function @code{my_print}, and the arguments to check 2052start with the third argument, so the correct parameters for the format 2053attribute are 2 and 3. 2054 2055@opindex ffreestanding 2056The @code{format} attribute allows you to identify your own functions 2057which take format strings as arguments, so that GCC can check the 2058calls to these functions for errors. The compiler always (unless 2059@option{-ffreestanding} is used) checks formats 2060for the standard library functions @code{printf}, @code{fprintf}, 2061@code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime}, 2062@code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such 2063warnings are requested (using @option{-Wformat}), so there is no need to 2064modify the header file @file{stdio.h}. In C99 mode, the functions 2065@code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and 2066@code{vsscanf} are also checked. Except in strictly conforming C 2067standard modes, the X/Open function @code{strfmon} is also checked as 2068are @code{printf_unlocked} and @code{fprintf_unlocked}. 2069@xref{C Dialect Options,,Options Controlling C Dialect}. 2070 2071@item format_arg (@var{string-index}) 2072@cindex @code{format_arg} function attribute 2073@opindex Wformat-nonliteral 2074The @code{format_arg} attribute specifies that a function takes a format 2075string for a @code{printf}, @code{scanf}, @code{strftime} or 2076@code{strfmon} style function and modifies it (for example, to translate 2077it into another language), so the result can be passed to a 2078@code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style 2079function (with the remaining arguments to the format function the same 2080as they would have been for the unmodified string). For example, the 2081declaration: 2082 2083@smallexample 2084extern char * 2085my_dgettext (char *my_domain, const char *my_format) 2086 __attribute__ ((format_arg (2))); 2087@end smallexample 2088 2089@noindent 2090causes the compiler to check the arguments in calls to a @code{printf}, 2091@code{scanf}, @code{strftime} or @code{strfmon} type function, whose 2092format string argument is a call to the @code{my_dgettext} function, for 2093consistency with the format string argument @code{my_format}. If the 2094@code{format_arg} attribute had not been specified, all the compiler 2095could tell in such calls to format functions would be that the format 2096string argument is not constant; this would generate a warning when 2097@option{-Wformat-nonliteral} is used, but the calls could not be checked 2098without the attribute. 2099 2100The parameter @var{string-index} specifies which argument is the format 2101string argument (starting from 1). 2102 2103The @code{format-arg} attribute allows you to identify your own 2104functions which modify format strings, so that GCC can check the 2105calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} 2106type function whose operands are a call to one of your own function. 2107The compiler always treats @code{gettext}, @code{dgettext}, and 2108@code{dcgettext} in this manner except when strict ISO C support is 2109requested by @option{-ansi} or an appropriate @option{-std} option, or 2110@option{-ffreestanding} is used. @xref{C Dialect Options,,Options 2111Controlling C Dialect}. 2112 2113@item no_instrument_function 2114@cindex @code{no_instrument_function} function attribute 2115@opindex finstrument-functions 2116If @option{-finstrument-functions} is given, profiling function calls will 2117be generated at entry and exit of most user-compiled functions. 2118Functions with this attribute will not be so instrumented. 2119 2120@item section ("@var{section-name}") 2121@cindex @code{section} function attribute 2122Normally, the compiler places the code it generates in the @code{text} section. 2123Sometimes, however, you need additional sections, or you need certain 2124particular functions to appear in special sections. The @code{section} 2125attribute specifies that a function lives in a particular section. 2126For example, the declaration: 2127 2128@smallexample 2129extern void foobar (void) __attribute__ ((section ("bar"))); 2130@end smallexample 2131 2132@noindent 2133puts the function @code{foobar} in the @code{bar} section. 2134 2135Some file formats do not support arbitrary sections so the @code{section} 2136attribute is not available on all platforms. 2137If you need to map the entire contents of a module to a particular 2138section, consider using the facilities of the linker instead. 2139 2140@item constructor 2141@itemx destructor 2142@cindex @code{constructor} function attribute 2143@cindex @code{destructor} function attribute 2144The @code{constructor} attribute causes the function to be called 2145automatically before execution enters @code{main ()}. Similarly, the 2146@code{destructor} attribute causes the function to be called 2147automatically after @code{main ()} has completed or @code{exit ()} has 2148been called. Functions with these attributes are useful for 2149initializing data that will be used implicitly during the execution of 2150the program. 2151 2152These attributes are not currently implemented for Objective-C@. 2153 2154@cindex @code{unused} attribute. 2155@item unused 2156This attribute, attached to a function, means that the function is meant 2157to be possibly unused. GCC will not produce a warning for this 2158function. GNU C++ does not currently support this attribute as 2159definitions without parameters are valid in C++. 2160 2161@cindex @code{used} attribute. 2162@item used 2163This attribute, attached to a function, means that code must be emitted 2164for the function even if it appears that the function is not referenced. 2165This is useful, for example, when the function is referenced only in 2166inline assembly. 2167 2168@cindex @code{deprecated} attribute. 2169@item deprecated 2170The @code{deprecated} attribute results in a warning if the function 2171is used anywhere in the source file. This is useful when identifying 2172functions that are expected to be removed in a future version of a 2173program. The warning also includes the location of the declaration 2174of the deprecated function, to enable users to easily find further 2175information about why the function is deprecated, or what they should 2176do instead. Note that the warnings only occurs for uses: 2177 2178@smallexample 2179int old_fn () __attribute__ ((deprecated)); 2180int old_fn (); 2181int (*fn_ptr)() = old_fn; 2182@end smallexample 2183 2184results in a warning on line 3 but not line 2. 2185 2186The @code{deprecated} attribute can also be used for variables and 2187types (@pxref{Variable Attributes}, @pxref{Type Attributes}.) 2188 2189@item weak 2190@cindex @code{weak} attribute 2191The @code{weak} attribute causes the declaration to be emitted as a weak 2192symbol rather than a global. This is primarily useful in defining 2193library functions which can be overridden in user code, though it can 2194also be used with non-function declarations. Weak symbols are supported 2195for ELF targets, and also for a.out targets when using the GNU assembler 2196and linker. 2197 2198@item malloc 2199@cindex @code{malloc} attribute 2200The @code{malloc} attribute is used to tell the compiler that a function 2201may be treated as if it were the malloc function. The compiler assumes 2202that calls to malloc result in a pointers that cannot alias anything. 2203This will often improve optimization. 2204 2205@item alias ("@var{target}") 2206@cindex @code{alias} attribute 2207The @code{alias} attribute causes the declaration to be emitted as an 2208alias for another symbol, which must be specified. For instance, 2209 2210@smallexample 2211void __f () @{ /* do something */; @} 2212void f () __attribute__ ((weak, alias ("__f"))); 2213@end smallexample 2214 2215declares @samp{f} to be a weak alias for @samp{__f}. In C++, the 2216mangled name for the target must be used. 2217 2218Not all target machines support this attribute. 2219 2220@item regparm (@var{number}) 2221@cindex functions that are passed arguments in registers on the 386 2222On the Intel 386, the @code{regparm} attribute causes the compiler to 2223pass up to @var{number} integer arguments in registers EAX, 2224EDX, and ECX instead of on the stack. Functions that take a 2225variable number of arguments will continue to be passed all of their 2226arguments on the stack. 2227 2228@item stdcall 2229@cindex functions that pop the argument stack on the 386 2230On the Intel 386, the @code{stdcall} attribute causes the compiler to 2231assume that the called function will pop off the stack space used to 2232pass arguments, unless it takes a variable number of arguments. 2233 2234The PowerPC compiler for Windows NT currently ignores the @code{stdcall} 2235attribute. 2236 2237@item cdecl 2238@cindex functions that do pop the argument stack on the 386 2239@opindex mrtd 2240On the Intel 386, the @code{cdecl} attribute causes the compiler to 2241assume that the calling function will pop off the stack space used to 2242pass arguments. This is 2243useful to override the effects of the @option{-mrtd} switch. 2244 2245The PowerPC compiler for Windows NT currently ignores the @code{cdecl} 2246attribute. 2247 2248@item longcall 2249@cindex functions called via pointer on the RS/6000 and PowerPC 2250On the RS/6000 and PowerPC, the @code{longcall} attribute causes the 2251compiler to always call the function via a pointer, so that functions 2252which reside further than 64 megabytes (67,108,864 bytes) from the 2253current location can be called. 2254 2255@item long_call/short_call 2256@cindex indirect calls on ARM 2257This attribute allows to specify how to call a particular function on 2258ARM@. Both attributes override the @option{-mlong-calls} (@pxref{ARM Options}) 2259command line switch and @code{#pragma long_calls} settings. The 2260@code{long_call} attribute causes the compiler to always call the 2261function by first loading its address into a register and then using the 2262contents of that register. The @code{short_call} attribute always places 2263the offset to the function from the call site into the @samp{BL} 2264instruction directly. 2265 2266@item dllimport 2267@cindex functions which are imported from a dll on PowerPC Windows NT 2268On the PowerPC running Windows NT, the @code{dllimport} attribute causes 2269the compiler to call the function via a global pointer to the function 2270pointer that is set up by the Windows NT dll library. The pointer name 2271is formed by combining @code{__imp_} and the function name. 2272 2273@item dllexport 2274@cindex functions which are exported from a dll on PowerPC Windows NT 2275On the PowerPC running Windows NT, the @code{dllexport} attribute causes 2276the compiler to provide a global pointer to the function pointer, so 2277that it can be called with the @code{dllimport} attribute. The pointer 2278name is formed by combining @code{__imp_} and the function name. 2279 2280@item exception (@var{except-func} [, @var{except-arg}]) 2281@cindex functions which specify exception handling on PowerPC Windows NT 2282On the PowerPC running Windows NT, the @code{exception} attribute causes 2283the compiler to modify the structured exception table entry it emits for 2284the declared function. The string or identifier @var{except-func} is 2285placed in the third entry of the structured exception table. It 2286represents a function, which is called by the exception handling 2287mechanism if an exception occurs. If it was specified, the string or 2288identifier @var{except-arg} is placed in the fourth entry of the 2289structured exception table. 2290 2291@item function_vector 2292@cindex calling functions through the function vector on the H8/300 processors 2293Use this attribute on the H8/300 and H8/300H to indicate that the specified 2294function should be called through the function vector. Calling a 2295function through the function vector will reduce code size, however; 2296the function vector has a limited size (maximum 128 entries on the H8/300 2297and 64 entries on the H8/300H) and shares space with the interrupt vector. 2298 2299You must use GAS and GLD from GNU binutils version 2.7 or later for 2300this attribute to work correctly. 2301 2302@item interrupt 2303@cindex interrupt handler functions 2304Use this attribute on the ARM, AVR, M32R/D and Xstormy16 ports to indicate 2305that the specified function is an interrupt handler. The compiler will 2306generate function entry and exit sequences suitable for use in an 2307interrupt handler when this attribute is present. 2308 2309Note, interrupt handlers for the H8/300, H8/300H and SH processors can 2310be specified via the @code{interrupt_handler} attribute. 2311 2312Note, on the AVR interrupts will be enabled inside the function. 2313 2314Note, for the ARM you can specify the kind of interrupt to be handled by 2315adding an optional parameter to the interrupt attribute like this: 2316 2317@smallexample 2318void f () __attribute__ ((interrupt ("IRQ"))); 2319@end smallexample 2320 2321Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@. 2322 2323@item interrupt_handler 2324@cindex interrupt handler functions on the H8/300 and SH processors 2325Use this attribute on the H8/300, H8/300H and SH to indicate that the 2326specified function is an interrupt handler. The compiler will generate 2327function entry and exit sequences suitable for use in an interrupt 2328handler when this attribute is present. 2329 2330@item sp_switch 2331Use this attribute on the SH to indicate an @code{interrupt_handler} 2332function should switch to an alternate stack. It expects a string 2333argument that names a global variable holding the address of the 2334alternate stack. 2335 2336@smallexample 2337void *alt_stack; 2338void f () __attribute__ ((interrupt_handler, 2339 sp_switch ("alt_stack"))); 2340@end smallexample 2341 2342@item trap_exit 2343Use this attribute on the SH for an @code{interrupt_handle} to return using 2344@code{trapa} instead of @code{rte}. This attribute expects an integer 2345argument specifying the trap number to be used. 2346 2347@item eightbit_data 2348@cindex eight bit data on the H8/300 and H8/300H 2349Use this attribute on the H8/300 and H8/300H to indicate that the specified 2350variable should be placed into the eight bit data section. 2351The compiler will generate more efficient code for certain operations 2352on data in the eight bit data area. Note the eight bit data area is limited to 2353256 bytes of data. 2354 2355You must use GAS and GLD from GNU binutils version 2.7 or later for 2356this attribute to work correctly. 2357 2358@item tiny_data 2359@cindex tiny data section on the H8/300H 2360Use this attribute on the H8/300H to indicate that the specified 2361variable should be placed into the tiny data section. 2362The compiler will generate more efficient code for loads and stores 2363on data in the tiny data section. Note the tiny data area is limited to 2364slightly under 32kbytes of data. 2365 2366@item signal 2367@cindex signal handler functions on the AVR processors 2368Use this attribute on the AVR to indicate that the specified 2369function is an signal handler. The compiler will generate function 2370entry and exit sequences suitable for use in an signal handler when this 2371attribute is present. Interrupts will be disabled inside function. 2372 2373@item naked 2374@cindex function without a prologue/epilogue code 2375Use this attribute on the ARM or AVR ports to indicate that the specified 2376function do not need prologue/epilogue sequences generated by the 2377compiler. It is up to the programmer to provide these sequences. 2378 2379@item model (@var{model-name}) 2380@cindex function addressability on the M32R/D 2381Use this attribute on the M32R/D to set the addressability of an object, 2382and the code generated for a function. 2383The identifier @var{model-name} is one of @code{small}, @code{medium}, 2384or @code{large}, representing each of the code models. 2385 2386Small model objects live in the lower 16MB of memory (so that their 2387addresses can be loaded with the @code{ld24} instruction), and are 2388callable with the @code{bl} instruction. 2389 2390Medium model objects may live anywhere in the 32-bit address space (the 2391compiler will generate @code{seth/add3} instructions to load their addresses), 2392and are callable with the @code{bl} instruction. 2393 2394Large model objects may live anywhere in the 32-bit address space (the 2395compiler will generate @code{seth/add3} instructions to load their addresses), 2396and may not be reachable with the @code{bl} instruction (the compiler will 2397generate the much slower @code{seth/add3/jl} instruction sequence). 2398 2399@end table 2400 2401You can specify multiple attributes in a declaration by separating them 2402by commas within the double parentheses or by immediately following an 2403attribute declaration with another attribute declaration. 2404 2405@cindex @code{#pragma}, reason for not using 2406@cindex pragma, reason for not using 2407Some people object to the @code{__attribute__} feature, suggesting that 2408ISO C's @code{#pragma} should be used instead. At the time 2409@code{__attribute__} was designed, there were two reasons for not doing 2410this. 2411 2412@enumerate 2413@item 2414It is impossible to generate @code{#pragma} commands from a macro. 2415 2416@item 2417There is no telling what the same @code{#pragma} might mean in another 2418compiler. 2419@end enumerate 2420 2421These two reasons applied to almost any application that might have been 2422proposed for @code{#pragma}. It was basically a mistake to use 2423@code{#pragma} for @emph{anything}. 2424 2425The ISO C99 standard includes @code{_Pragma}, which now allows pragmas 2426to be generated from macros. In addition, a @code{#pragma GCC} 2427namespace is now in use for GCC-specific pragmas. However, it has been 2428found convenient to use @code{__attribute__} to achieve a natural 2429attachment of attributes to their corresponding declarations, whereas 2430@code{#pragma GCC} is of use for constructs that do not naturally form 2431part of the grammar. @xref{Other Directives,,Miscellaneous 2432Preprocessing Directives, cpp, The C Preprocessor}. 2433 2434@node Attribute Syntax 2435@section Attribute Syntax 2436@cindex attribute syntax 2437 2438This section describes the syntax with which @code{__attribute__} may be 2439used, and the constructs to which attribute specifiers bind, for the C 2440language. Some details may vary for C++ and Objective-C@. Because of 2441infelicities in the grammar for attributes, some forms described here 2442may not be successfully parsed in all cases. 2443 2444There are some problems with the semantics of attributes in C++. For 2445example, there are no manglings for attributes, although they may affect 2446code generation, so problems may arise when attributed types are used in 2447conjunction with templates or overloading. Similarly, @code{typeid} 2448does not distinguish between types with different attributes. Support 2449for attributes in C++ may be restricted in future to attributes on 2450declarations only, but not on nested declarators. 2451 2452@xref{Function Attributes}, for details of the semantics of attributes 2453applying to functions. @xref{Variable Attributes}, for details of the 2454semantics of attributes applying to variables. @xref{Type Attributes}, 2455for details of the semantics of attributes applying to structure, union 2456and enumerated types. 2457 2458An @dfn{attribute specifier} is of the form 2459@code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list} 2460is a possibly empty comma-separated sequence of @dfn{attributes}, where 2461each attribute is one of the following: 2462 2463@itemize @bullet 2464@item 2465Empty. Empty attributes are ignored. 2466 2467@item 2468A word (which may be an identifier such as @code{unused}, or a reserved 2469word such as @code{const}). 2470 2471@item 2472A word, followed by, in parentheses, parameters for the attribute. 2473These parameters take one of the following forms: 2474 2475@itemize @bullet 2476@item 2477An identifier. For example, @code{mode} attributes use this form. 2478 2479@item 2480An identifier followed by a comma and a non-empty comma-separated list 2481of expressions. For example, @code{format} attributes use this form. 2482 2483@item 2484A possibly empty comma-separated list of expressions. For example, 2485@code{format_arg} attributes use this form with the list being a single 2486integer constant expression, and @code{alias} attributes use this form 2487with the list being a single string constant. 2488@end itemize 2489@end itemize 2490 2491An @dfn{attribute specifier list} is a sequence of one or more attribute 2492specifiers, not separated by any other tokens. 2493 2494An attribute specifier list may appear after the colon following a 2495label, other than a @code{case} or @code{default} label. The only 2496attribute it makes sense to use after a label is @code{unused}. This 2497feature is intended for code generated by programs which contains labels 2498that may be unused but which is compiled with @option{-Wall}. It would 2499not normally be appropriate to use in it human-written code, though it 2500could be useful in cases where the code that jumps to the label is 2501contained within an @code{#ifdef} conditional. 2502 2503An attribute specifier list may appear as part of a @code{struct}, 2504@code{union} or @code{enum} specifier. It may go either immediately 2505after the @code{struct}, @code{union} or @code{enum} keyword, or after 2506the closing brace. It is ignored if the content of the structure, union 2507or enumerated type is not defined in the specifier in which the 2508attribute specifier list is used---that is, in usages such as 2509@code{struct __attribute__((foo)) bar} with no following opening brace. 2510Where attribute specifiers follow the closing brace, they are considered 2511to relate to the structure, union or enumerated type defined, not to any 2512enclosing declaration the type specifier appears in, and the type 2513defined is not complete until after the attribute specifiers. 2514@c Otherwise, there would be the following problems: a shift/reduce 2515@c conflict between attributes binding the struct/union/enum and 2516@c binding to the list of specifiers/qualifiers; and "aligned" 2517@c attributes could use sizeof for the structure, but the size could be 2518@c changed later by "packed" attributes. 2519 2520Otherwise, an attribute specifier appears as part of a declaration, 2521counting declarations of unnamed parameters and type names, and relates 2522to that declaration (which may be nested in another declaration, for 2523example in the case of a parameter declaration), or to a particular declarator 2524within a declaration. Where an 2525attribute specifier is applied to a parameter declared as a function or 2526an array, it should apply to the function or array rather than the 2527pointer to which the parameter is implicitly converted, but this is not 2528yet correctly implemented. 2529 2530Any list of specifiers and qualifiers at the start of a declaration may 2531contain attribute specifiers, whether or not such a list may in that 2532context contain storage class specifiers. (Some attributes, however, 2533are essentially in the nature of storage class specifiers, and only make 2534sense where storage class specifiers may be used; for example, 2535@code{section}.) There is one necessary limitation to this syntax: the 2536first old-style parameter declaration in a function definition cannot 2537begin with an attribute specifier, because such an attribute applies to 2538the function instead by syntax described below (which, however, is not 2539yet implemented in this case). In some other cases, attribute 2540specifiers are permitted by this grammar but not yet supported by the 2541compiler. All attribute specifiers in this place relate to the 2542declaration as a whole. In the obsolescent usage where a type of 2543@code{int} is implied by the absence of type specifiers, such a list of 2544specifiers and qualifiers may be an attribute specifier list with no 2545other specifiers or qualifiers. 2546 2547An attribute specifier list may appear immediately before a declarator 2548(other than the first) in a comma-separated list of declarators in a 2549declaration of more than one identifier using a single list of 2550specifiers and qualifiers. Such attribute specifiers apply 2551only to the identifier before whose declarator they appear. For 2552example, in 2553 2554@smallexample 2555__attribute__((noreturn)) void d0 (void), 2556 __attribute__((format(printf, 1, 2))) d1 (const char *, ...), 2557 d2 (void) 2558@end smallexample 2559 2560@noindent 2561the @code{noreturn} attribute applies to all the functions 2562declared; the @code{format} attribute only applies to @code{d1}. 2563 2564An attribute specifier list may appear immediately before the comma, 2565@code{=} or semicolon terminating the declaration of an identifier other 2566than a function definition. At present, such attribute specifiers apply 2567to the declared object or function, but in future they may attach to the 2568outermost adjacent declarator. In simple cases there is no difference, 2569but, for example, in 2570 2571@smallexample 2572void (****f)(void) __attribute__((noreturn)); 2573@end smallexample 2574 2575@noindent 2576at present the @code{noreturn} attribute applies to @code{f}, which 2577causes a warning since @code{f} is not a function, but in future it may 2578apply to the function @code{****f}. The precise semantics of what 2579attributes in such cases will apply to are not yet specified. Where an 2580assembler name for an object or function is specified (@pxref{Asm 2581Labels}), at present the attribute must follow the @code{asm} 2582specification; in future, attributes before the @code{asm} specification 2583may apply to the adjacent declarator, and those after it to the declared 2584object or function. 2585 2586An attribute specifier list may, in future, be permitted to appear after 2587the declarator in a function definition (before any old-style parameter 2588declarations or the function body). 2589 2590Attribute specifiers may be mixed with type qualifiers appearing inside 2591the @code{[]} of a parameter array declarator, in the C99 construct by 2592which such qualifiers are applied to the pointer to which the array is 2593implicitly converted. Such attribute specifiers apply to the pointer, 2594not to the array, but at present this is not implemented and they are 2595ignored. 2596 2597An attribute specifier list may appear at the start of a nested 2598declarator. At present, there are some limitations in this usage: the 2599attributes correctly apply to the declarator, but for most individual 2600attributes the semantics this implies are not implemented. 2601When attribute specifiers follow the @code{*} of a pointer 2602declarator, they may be mixed with any type qualifiers present. 2603The following describes the formal semantics of this syntax. It will make the 2604most sense if you are familiar with the formal specification of 2605declarators in the ISO C standard. 2606 2607Consider (as in C99 subclause 6.7.5 paragraph 4) a declaration @code{T 2608D1}, where @code{T} contains declaration specifiers that specify a type 2609@var{Type} (such as @code{int}) and @code{D1} is a declarator that 2610contains an identifier @var{ident}. The type specified for @var{ident} 2611for derived declarators whose type does not include an attribute 2612specifier is as in the ISO C standard. 2613 2614If @code{D1} has the form @code{( @var{attribute-specifier-list} D )}, 2615and the declaration @code{T D} specifies the type 2616``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then 2617@code{T D1} specifies the type ``@var{derived-declarator-type-list} 2618@var{attribute-specifier-list} @var{Type}'' for @var{ident}. 2619 2620If @code{D1} has the form @code{* 2621@var{type-qualifier-and-attribute-specifier-list} D}, and the 2622declaration @code{T D} specifies the type 2623``@var{derived-declarator-type-list} @var{Type}'' for @var{ident}, then 2624@code{T D1} specifies the type ``@var{derived-declarator-type-list} 2625@var{type-qualifier-and-attribute-specifier-list} @var{Type}'' for 2626@var{ident}. 2627 2628For example, 2629 2630@smallexample 2631void (__attribute__((noreturn)) ****f) (void); 2632@end smallexample 2633 2634@noindent 2635specifies the type ``pointer to pointer to pointer to pointer to 2636non-returning function returning @code{void}''. As another example, 2637 2638@smallexample 2639char *__attribute__((aligned(8))) *f; 2640@end smallexample 2641 2642@noindent 2643specifies the type ``pointer to 8-byte-aligned pointer to @code{char}''. 2644Note again that this does not work with most attributes; for example, 2645the usage of @samp{aligned} and @samp{noreturn} attributes given above 2646is not yet supported. 2647 2648For compatibility with existing code written for compiler versions that 2649did not implement attributes on nested declarators, some laxity is 2650allowed in the placing of attributes. If an attribute that only applies 2651to types is applied to a declaration, it will be treated as applying to 2652the type of that declaration. If an attribute that only applies to 2653declarations is applied to the type of a declaration, it will be treated 2654as applying to that declaration; and, for compatibility with code 2655placing the attributes immediately before the identifier declared, such 2656an attribute applied to a function return type will be treated as 2657applying to the function type, and such an attribute applied to an array 2658element type will be treated as applying to the array type. If an 2659attribute that only applies to function types is applied to a 2660pointer-to-function type, it will be treated as applying to the pointer 2661target type; if such an attribute is applied to a function return type 2662that is not a pointer-to-function type, it will be treated as applying 2663to the function type. 2664 2665@node Function Prototypes 2666@section Prototypes and Old-Style Function Definitions 2667@cindex function prototype declarations 2668@cindex old-style function definitions 2669@cindex promotion of formal parameters 2670 2671GNU C extends ISO C to allow a function prototype to override a later 2672old-style non-prototype definition. Consider the following example: 2673 2674@example 2675/* @r{Use prototypes unless the compiler is old-fashioned.} */ 2676#ifdef __STDC__ 2677#define P(x) x 2678#else 2679#define P(x) () 2680#endif 2681 2682/* @r{Prototype function declaration.} */ 2683int isroot P((uid_t)); 2684 2685/* @r{Old-style function definition.} */ 2686int 2687isroot (x) /* ??? lossage here ??? */ 2688 uid_t x; 2689@{ 2690 return x == 0; 2691@} 2692@end example 2693 2694Suppose the type @code{uid_t} happens to be @code{short}. ISO C does 2695not allow this example, because subword arguments in old-style 2696non-prototype definitions are promoted. Therefore in this example the 2697function definition's argument is really an @code{int}, which does not 2698match the prototype argument type of @code{short}. 2699 2700This restriction of ISO C makes it hard to write code that is portable 2701to traditional C compilers, because the programmer does not know 2702whether the @code{uid_t} type is @code{short}, @code{int}, or 2703@code{long}. Therefore, in cases like these GNU C allows a prototype 2704to override a later old-style definition. More precisely, in GNU C, a 2705function prototype argument type overrides the argument type specified 2706by a later old-style definition if the former type is the same as the 2707latter type before promotion. Thus in GNU C the above example is 2708equivalent to the following: 2709 2710@example 2711int isroot (uid_t); 2712 2713int 2714isroot (uid_t x) 2715@{ 2716 return x == 0; 2717@} 2718@end example 2719 2720@noindent 2721GNU C++ does not support old-style function definitions, so this 2722extension is irrelevant. 2723 2724@node C++ Comments 2725@section C++ Style Comments 2726@cindex // 2727@cindex C++ comments 2728@cindex comments, C++ style 2729 2730In GNU C, you may use C++ style comments, which start with @samp{//} and 2731continue until the end of the line. Many other C implementations allow 2732such comments, and they are likely to be in a future C standard. 2733However, C++ style comments are not recognized if you specify 2734@w{@option{-ansi}}, a @option{-std} option specifying a version of ISO C 2735before C99, or @w{@option{-traditional}}, since they are incompatible 2736with traditional constructs like @code{dividend//*comment*/divisor}. 2737 2738@node Dollar Signs 2739@section Dollar Signs in Identifier Names 2740@cindex $ 2741@cindex dollar signs in identifier names 2742@cindex identifier names, dollar signs in 2743 2744In GNU C, you may normally use dollar signs in identifier names. 2745This is because many traditional C implementations allow such identifiers. 2746However, dollar signs in identifiers are not supported on a few target 2747machines, typically because the target assembler does not allow them. 2748 2749@node Character Escapes 2750@section The Character @key{ESC} in Constants 2751 2752You can use the sequence @samp{\e} in a string or character constant to 2753stand for the ASCII character @key{ESC}. 2754 2755@node Alignment 2756@section Inquiring on Alignment of Types or Variables 2757@cindex alignment 2758@cindex type alignment 2759@cindex variable alignment 2760 2761The keyword @code{__alignof__} allows you to inquire about how an object 2762is aligned, or the minimum alignment usually required by a type. Its 2763syntax is just like @code{sizeof}. 2764 2765For example, if the target machine requires a @code{double} value to be 2766aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8. 2767This is true on many RISC machines. On more traditional machine 2768designs, @code{__alignof__ (double)} is 4 or even 2. 2769 2770Some machines never actually require alignment; they allow reference to any 2771data type even at an odd addresses. For these machines, @code{__alignof__} 2772reports the @emph{recommended} alignment of a type. 2773 2774If the operand of @code{__alignof__} is an lvalue rather than a type, 2775its value is the required alignment for its type, taking into account 2776any minimum alignment specified with GCC's @code{__attribute__} 2777extension (@pxref{Variable Attributes}). For example, after this 2778declaration: 2779 2780@example 2781struct foo @{ int x; char y; @} foo1; 2782@end example 2783 2784@noindent 2785the value of @code{__alignof__ (foo1.y)} is 1, even though its actual 2786alignment is probably 2 or 4, the same as @code{__alignof__ (int)}. 2787 2788It is an error to ask for the alignment of an incomplete type. 2789 2790@node Variable Attributes 2791@section Specifying Attributes of Variables 2792@cindex attribute of variables 2793@cindex variable attributes 2794 2795The keyword @code{__attribute__} allows you to specify special 2796attributes of variables or structure fields. This keyword is followed 2797by an attribute specification inside double parentheses. Ten 2798attributes are currently defined for variables: @code{aligned}, 2799@code{mode}, @code{nocommon}, @code{packed}, @code{section}, 2800@code{transparent_union}, @code{unused}, @code{deprecated}, 2801@code{vector_size}, and @code{weak}. Some other attributes are defined 2802for variables on particular target systems. Other attributes are 2803available for functions (@pxref{Function Attributes}) and for types 2804(@pxref{Type Attributes}). Other front ends might define more 2805attributes (@pxref{C++ Extensions,,Extensions to the C++ Language}). 2806 2807You may also specify attributes with @samp{__} preceding and following 2808each keyword. This allows you to use them in header files without 2809being concerned about a possible macro of the same name. For example, 2810you may use @code{__aligned__} instead of @code{aligned}. 2811 2812@xref{Attribute Syntax}, for details of the exact syntax for using 2813attributes. 2814 2815@table @code 2816@cindex @code{aligned} attribute 2817@item aligned (@var{alignment}) 2818This attribute specifies a minimum alignment for the variable or 2819structure field, measured in bytes. For example, the declaration: 2820 2821@smallexample 2822int x __attribute__ ((aligned (16))) = 0; 2823@end smallexample 2824 2825@noindent 2826causes the compiler to allocate the global variable @code{x} on a 282716-byte boundary. On a 68040, this could be used in conjunction with 2828an @code{asm} expression to access the @code{move16} instruction which 2829requires 16-byte aligned operands. 2830 2831You can also specify the alignment of structure fields. For example, to 2832create a double-word aligned @code{int} pair, you could write: 2833 2834@smallexample 2835struct foo @{ int x[2] __attribute__ ((aligned (8))); @}; 2836@end smallexample 2837 2838@noindent 2839This is an alternative to creating a union with a @code{double} member 2840that forces the union to be double-word aligned. 2841 2842As in the preceding examples, you can explicitly specify the alignment 2843(in bytes) that you wish the compiler to use for a given variable or 2844structure field. Alternatively, you can leave out the alignment factor 2845and just ask the compiler to align a variable or field to the maximum 2846useful alignment for the target machine you are compiling for. For 2847example, you could write: 2848 2849@smallexample 2850short array[3] __attribute__ ((aligned)); 2851@end smallexample 2852 2853Whenever you leave out the alignment factor in an @code{aligned} attribute 2854specification, the compiler automatically sets the alignment for the declared 2855variable or field to the largest alignment which is ever used for any data 2856type on the target machine you are compiling for. Doing this can often make 2857copy operations more efficient, because the compiler can use whatever 2858instructions copy the biggest chunks of memory when performing copies to 2859or from the variables or fields that you have aligned this way. 2860 2861The @code{aligned} attribute can only increase the alignment; but you 2862can decrease it by specifying @code{packed} as well. See below. 2863 2864Note that the effectiveness of @code{aligned} attributes may be limited 2865by inherent limitations in your linker. On many systems, the linker is 2866only able to arrange for variables to be aligned up to a certain maximum 2867alignment. (For some linkers, the maximum supported alignment may 2868be very very small.) If your linker is only able to align variables 2869up to a maximum of 8 byte alignment, then specifying @code{aligned(16)} 2870in an @code{__attribute__} will still only provide you with 8 byte 2871alignment. See your linker documentation for further information. 2872 2873@item mode (@var{mode}) 2874@cindex @code{mode} attribute 2875This attribute specifies the data type for the declaration---whichever 2876type corresponds to the mode @var{mode}. This in effect lets you 2877request an integer or floating point type according to its width. 2878 2879You may also specify a mode of @samp{byte} or @samp{__byte__} to 2880indicate the mode corresponding to a one-byte integer, @samp{word} or 2881@samp{__word__} for the mode of a one-word integer, and @samp{pointer} 2882or @samp{__pointer__} for the mode used to represent pointers. 2883 2884@item nocommon 2885@cindex @code{nocommon} attribute 2886@opindex fno-common 2887This attribute specifies requests GCC not to place a variable 2888``common'' but instead to allocate space for it directly. If you 2889specify the @option{-fno-common} flag, GCC will do this for all 2890variables. 2891 2892Specifying the @code{nocommon} attribute for a variable provides an 2893initialization of zeros. A variable may only be initialized in one 2894source file. 2895 2896@item packed 2897@cindex @code{packed} attribute 2898The @code{packed} attribute specifies that a variable or structure field 2899should have the smallest possible alignment---one byte for a variable, 2900and one bit for a field, unless you specify a larger value with the 2901@code{aligned} attribute. 2902 2903Here is a structure in which the field @code{x} is packed, so that it 2904immediately follows @code{a}: 2905 2906@example 2907struct foo 2908@{ 2909 char a; 2910 int x[2] __attribute__ ((packed)); 2911@}; 2912@end example 2913 2914@item section ("@var{section-name}") 2915@cindex @code{section} variable attribute 2916Normally, the compiler places the objects it generates in sections like 2917@code{data} and @code{bss}. Sometimes, however, you need additional sections, 2918or you need certain particular variables to appear in special sections, 2919for example to map to special hardware. The @code{section} 2920attribute specifies that a variable (or function) lives in a particular 2921section. For example, this small program uses several specific section names: 2922 2923@smallexample 2924struct duart a __attribute__ ((section ("DUART_A"))) = @{ 0 @}; 2925struct duart b __attribute__ ((section ("DUART_B"))) = @{ 0 @}; 2926char stack[10000] __attribute__ ((section ("STACK"))) = @{ 0 @}; 2927int init_data __attribute__ ((section ("INITDATA"))) = 0; 2928 2929main() 2930@{ 2931 /* Initialize stack pointer */ 2932 init_sp (stack + sizeof (stack)); 2933 2934 /* Initialize initialized data */ 2935 memcpy (&init_data, &data, &edata - &data); 2936 2937 /* Turn on the serial ports */ 2938 init_duart (&a); 2939 init_duart (&b); 2940@} 2941@end smallexample 2942 2943@noindent 2944Use the @code{section} attribute with an @emph{initialized} definition 2945of a @emph{global} variable, as shown in the example. GCC issues 2946a warning and otherwise ignores the @code{section} attribute in 2947uninitialized variable declarations. 2948 2949You may only use the @code{section} attribute with a fully initialized 2950global definition because of the way linkers work. The linker requires 2951each object be defined once, with the exception that uninitialized 2952variables tentatively go in the @code{common} (or @code{bss}) section 2953and can be multiply ``defined''. You can force a variable to be 2954initialized with the @option{-fno-common} flag or the @code{nocommon} 2955attribute. 2956 2957Some file formats do not support arbitrary sections so the @code{section} 2958attribute is not available on all platforms. 2959If you need to map the entire contents of a module to a particular 2960section, consider using the facilities of the linker instead. 2961 2962@item shared 2963@cindex @code{shared} variable attribute 2964On Windows NT, in addition to putting variable definitions in a named 2965section, the section can also be shared among all running copies of an 2966executable or DLL@. For example, this small program defines shared data 2967by putting it in a named section @code{shared} and marking the section 2968shareable: 2969 2970@smallexample 2971int foo __attribute__((section ("shared"), shared)) = 0; 2972 2973int 2974main() 2975@{ 2976 /* Read and write foo. All running 2977 copies see the same value. */ 2978 return 0; 2979@} 2980@end smallexample 2981 2982@noindent 2983You may only use the @code{shared} attribute along with @code{section} 2984attribute with a fully initialized global definition because of the way 2985linkers work. See @code{section} attribute for more information. 2986 2987The @code{shared} attribute is only available on Windows NT@. 2988 2989@item transparent_union 2990This attribute, attached to a function parameter which is a union, means 2991that the corresponding argument may have the type of any union member, 2992but the argument is passed as if its type were that of the first union 2993member. For more details see @xref{Type Attributes}. You can also use 2994this attribute on a @code{typedef} for a union data type; then it 2995applies to all function parameters with that type. 2996 2997@item unused 2998This attribute, attached to a variable, means that the variable is meant 2999to be possibly unused. GCC will not produce a warning for this 3000variable. 3001 3002@item deprecated 3003The @code{deprecated} attribute results in a warning if the variable 3004is used anywhere in the source file. This is useful when identifying 3005variables that are expected to be removed in a future version of a 3006program. The warning also includes the location of the declaration 3007of the deprecated variable, to enable users to easily find further 3008information about why the variable is deprecated, or what they should 3009do instead. Note that the warnings only occurs for uses: 3010 3011@smallexample 3012extern int old_var __attribute__ ((deprecated)); 3013extern int old_var; 3014int new_fn () @{ return old_var; @} 3015@end smallexample 3016 3017results in a warning on line 3 but not line 2. 3018 3019The @code{deprecated} attribute can also be used for functions and 3020types (@pxref{Function Attributes}, @pxref{Type Attributes}.) 3021 3022@item vector_size (@var{bytes}) 3023This attribute specifies the vector size for the variable, measured in 3024bytes. For example, the declaration: 3025 3026@smallexample 3027int foo __attribute__ ((vector_size (16))); 3028@end smallexample 3029 3030@noindent 3031causes the compiler to set the mode for @code{foo}, to be 16 bytes, 3032divided into @code{int} sized units. Assuming a 32-bit int (a vector of 30334 units of 4 bytes), the corresponding mode of @code{foo} will be V4SI@. 3034 3035This attribute is only applicable to integral and float scalars, 3036although arrays, pointers, and function return values are allowed in 3037conjunction with this construct. 3038 3039Aggregates with this attribute are invalid, even if they are of the same 3040size as a corresponding scalar. For example, the declaration: 3041 3042@smallexample 3043struct S @{ int a; @}; 3044struct S __attribute__ ((vector_size (16))) foo; 3045@end smallexample 3046 3047@noindent 3048is invalid even if the size of the structure is the same as the size of 3049the @code{int}. 3050 3051@item weak 3052The @code{weak} attribute is described in @xref{Function Attributes}. 3053 3054@item model (@var{model-name}) 3055@cindex variable addressability on the M32R/D 3056Use this attribute on the M32R/D to set the addressability of an object. 3057The identifier @var{model-name} is one of @code{small}, @code{medium}, 3058or @code{large}, representing each of the code models. 3059 3060Small model objects live in the lower 16MB of memory (so that their 3061addresses can be loaded with the @code{ld24} instruction). 3062 3063Medium and large model objects may live anywhere in the 32-bit address space 3064(the compiler will generate @code{seth/add3} instructions to load their 3065addresses). 3066 3067@end table 3068 3069To specify multiple attributes, separate them by commas within the 3070double parentheses: for example, @samp{__attribute__ ((aligned (16), 3071packed))}. 3072 3073@node Type Attributes 3074@section Specifying Attributes of Types 3075@cindex attribute of types 3076@cindex type attributes 3077 3078The keyword @code{__attribute__} allows you to specify special 3079attributes of @code{struct} and @code{union} types when you define such 3080types. This keyword is followed by an attribute specification inside 3081double parentheses. Five attributes are currently defined for types: 3082@code{aligned}, @code{packed}, @code{transparent_union}, @code{unused}, 3083and @code{deprecated}. Other attributes are defined for functions 3084(@pxref{Function Attributes}) and for variables (@pxref{Variable Attributes}). 3085 3086You may also specify any one of these attributes with @samp{__} 3087preceding and following its keyword. This allows you to use these 3088attributes in header files without being concerned about a possible 3089macro of the same name. For example, you may use @code{__aligned__} 3090instead of @code{aligned}. 3091 3092You may specify the @code{aligned} and @code{transparent_union} 3093attributes either in a @code{typedef} declaration or just past the 3094closing curly brace of a complete enum, struct or union type 3095@emph{definition} and the @code{packed} attribute only past the closing 3096brace of a definition. 3097 3098You may also specify attributes between the enum, struct or union 3099tag and the name of the type rather than after the closing brace. 3100 3101@xref{Attribute Syntax}, for details of the exact syntax for using 3102attributes. 3103 3104@table @code 3105@cindex @code{aligned} attribute 3106@item aligned (@var{alignment}) 3107This attribute specifies a minimum alignment (in bytes) for variables 3108of the specified type. For example, the declarations: 3109 3110@smallexample 3111struct S @{ short f[3]; @} __attribute__ ((aligned (8))); 3112typedef int more_aligned_int __attribute__ ((aligned (8))); 3113@end smallexample 3114 3115@noindent 3116force the compiler to insure (as far as it can) that each variable whose 3117type is @code{struct S} or @code{more_aligned_int} will be allocated and 3118aligned @emph{at least} on a 8-byte boundary. On a Sparc, having all 3119variables of type @code{struct S} aligned to 8-byte boundaries allows 3120the compiler to use the @code{ldd} and @code{std} (doubleword load and 3121store) instructions when copying one variable of type @code{struct S} to 3122another, thus improving run-time efficiency. 3123 3124Note that the alignment of any given @code{struct} or @code{union} type 3125is required by the ISO C standard to be at least a perfect multiple of 3126the lowest common multiple of the alignments of all of the members of 3127the @code{struct} or @code{union} in question. This means that you @emph{can} 3128effectively adjust the alignment of a @code{struct} or @code{union} 3129type by attaching an @code{aligned} attribute to any one of the members 3130of such a type, but the notation illustrated in the example above is a 3131more obvious, intuitive, and readable way to request the compiler to 3132adjust the alignment of an entire @code{struct} or @code{union} type. 3133 3134As in the preceding example, you can explicitly specify the alignment 3135(in bytes) that you wish the compiler to use for a given @code{struct} 3136or @code{union} type. Alternatively, you can leave out the alignment factor 3137and just ask the compiler to align a type to the maximum 3138useful alignment for the target machine you are compiling for. For 3139example, you could write: 3140 3141@smallexample 3142struct S @{ short f[3]; @} __attribute__ ((aligned)); 3143@end smallexample 3144 3145Whenever you leave out the alignment factor in an @code{aligned} 3146attribute specification, the compiler automatically sets the alignment 3147for the type to the largest alignment which is ever used for any data 3148type on the target machine you are compiling for. Doing this can often 3149make copy operations more efficient, because the compiler can use 3150whatever instructions copy the biggest chunks of memory when performing 3151copies to or from the variables which have types that you have aligned 3152this way. 3153 3154In the example above, if the size of each @code{short} is 2 bytes, then 3155the size of the entire @code{struct S} type is 6 bytes. The smallest 3156power of two which is greater than or equal to that is 8, so the 3157compiler sets the alignment for the entire @code{struct S} type to 8 3158bytes. 3159 3160Note that although you can ask the compiler to select a time-efficient 3161alignment for a given type and then declare only individual stand-alone 3162objects of that type, the compiler's ability to select a time-efficient 3163alignment is primarily useful only when you plan to create arrays of 3164variables having the relevant (efficiently aligned) type. If you 3165declare or use arrays of variables of an efficiently-aligned type, then 3166it is likely that your program will also be doing pointer arithmetic (or 3167subscripting, which amounts to the same thing) on pointers to the 3168relevant type, and the code that the compiler generates for these 3169pointer arithmetic operations will often be more efficient for 3170efficiently-aligned types than for other types. 3171 3172The @code{aligned} attribute can only increase the alignment; but you 3173can decrease it by specifying @code{packed} as well. See below. 3174 3175Note that the effectiveness of @code{aligned} attributes may be limited 3176by inherent limitations in your linker. On many systems, the linker is 3177only able to arrange for variables to be aligned up to a certain maximum 3178alignment. (For some linkers, the maximum supported alignment may 3179be very very small.) If your linker is only able to align variables 3180up to a maximum of 8 byte alignment, then specifying @code{aligned(16)} 3181in an @code{__attribute__} will still only provide you with 8 byte 3182alignment. See your linker documentation for further information. 3183 3184@item packed 3185This attribute, attached to an @code{enum}, @code{struct}, or 3186@code{union} type definition, specified that the minimum required memory 3187be used to represent the type. 3188 3189@opindex fshort-enums 3190Specifying this attribute for @code{struct} and @code{union} types is 3191equivalent to specifying the @code{packed} attribute on each of the 3192structure or union members. Specifying the @option{-fshort-enums} 3193flag on the line is equivalent to specifying the @code{packed} 3194attribute on all @code{enum} definitions. 3195 3196You may only specify this attribute after a closing curly brace on an 3197@code{enum} definition, not in a @code{typedef} declaration, unless that 3198declaration also contains the definition of the @code{enum}. 3199 3200@item transparent_union 3201This attribute, attached to a @code{union} type definition, indicates 3202that any function parameter having that union type causes calls to that 3203function to be treated in a special way. 3204 3205First, the argument corresponding to a transparent union type can be of 3206any type in the union; no cast is required. Also, if the union contains 3207a pointer type, the corresponding argument can be a null pointer 3208constant or a void pointer expression; and if the union contains a void 3209pointer type, the corresponding argument can be any pointer expression. 3210If the union member type is a pointer, qualifiers like @code{const} on 3211the referenced type must be respected, just as with normal pointer 3212conversions. 3213 3214Second, the argument is passed to the function using the calling 3215conventions of first member of the transparent union, not the calling 3216conventions of the union itself. All members of the union must have the 3217same machine representation; this is necessary for this argument passing 3218to work properly. 3219 3220Transparent unions are designed for library functions that have multiple 3221interfaces for compatibility reasons. For example, suppose the 3222@code{wait} function must accept either a value of type @code{int *} to 3223comply with Posix, or a value of type @code{union wait *} to comply with 3224the 4.1BSD interface. If @code{wait}'s parameter were @code{void *}, 3225@code{wait} would accept both kinds of arguments, but it would also 3226accept any other pointer type and this would make argument type checking 3227less useful. Instead, @code{<sys/wait.h>} might define the interface 3228as follows: 3229 3230@smallexample 3231typedef union 3232 @{ 3233 int *__ip; 3234 union wait *__up; 3235 @} wait_status_ptr_t __attribute__ ((__transparent_union__)); 3236 3237pid_t wait (wait_status_ptr_t); 3238@end smallexample 3239 3240This interface allows either @code{int *} or @code{union wait *} 3241arguments to be passed, using the @code{int *} calling convention. 3242The program can call @code{wait} with arguments of either type: 3243 3244@example 3245int w1 () @{ int w; return wait (&w); @} 3246int w2 () @{ union wait w; return wait (&w); @} 3247@end example 3248 3249With this interface, @code{wait}'s implementation might look like this: 3250 3251@example 3252pid_t wait (wait_status_ptr_t p) 3253@{ 3254 return waitpid (-1, p.__ip, 0); 3255@} 3256@end example 3257 3258@item unused 3259When attached to a type (including a @code{union} or a @code{struct}), 3260this attribute means that variables of that type are meant to appear 3261possibly unused. GCC will not produce a warning for any variables of 3262that type, even if the variable appears to do nothing. This is often 3263the case with lock or thread classes, which are usually defined and then 3264not referenced, but contain constructors and destructors that have 3265nontrivial bookkeeping functions. 3266 3267@item deprecated 3268The @code{deprecated} attribute results in a warning if the type 3269is used anywhere in the source file. This is useful when identifying 3270types that are expected to be removed in a future version of a program. 3271If possible, the warning also includes the location of the declaration 3272of the deprecated type, to enable users to easily find further 3273information about why the type is deprecated, or what they should do 3274instead. Note that the warnings only occur for uses and then only 3275if the type is being applied to an identifier that itself is not being 3276declared as deprecated. 3277 3278@smallexample 3279typedef int T1 __attribute__ ((deprecated)); 3280T1 x; 3281typedef T1 T2; 3282T2 y; 3283typedef T1 T3 __attribute__ ((deprecated)); 3284T3 z __attribute__ ((deprecated)); 3285@end smallexample 3286 3287results in a warning on line 2 and 3 but not lines 4, 5, or 6. No 3288warning is issued for line 4 because T2 is not explicitly 3289deprecated. Line 5 has no warning because T3 is explicitly 3290deprecated. Similarly for line 6. 3291 3292The @code{deprecated} attribute can also be used for functions and 3293variables (@pxref{Function Attributes}, @pxref{Variable Attributes}.) 3294 3295@end table 3296 3297To specify multiple attributes, separate them by commas within the 3298double parentheses: for example, @samp{__attribute__ ((aligned (16), 3299packed))}. 3300 3301@node Inline 3302@section An Inline Function is As Fast As a Macro 3303@cindex inline functions 3304@cindex integrating function code 3305@cindex open coding 3306@cindex macros, inline alternative 3307 3308By declaring a function @code{inline}, you can direct GCC to 3309integrate that function's code into the code for its callers. This 3310makes execution faster by eliminating the function-call overhead; in 3311addition, if any of the actual argument values are constant, their known 3312values may permit simplifications at compile time so that not all of the 3313inline function's code needs to be included. The effect on code size is 3314less predictable; object code may be larger or smaller with function 3315inlining, depending on the particular case. Inlining of functions is an 3316optimization and it really ``works'' only in optimizing compilation. If 3317you don't use @option{-O}, no function is really inline. 3318 3319Inline functions are included in the ISO C99 standard, but there are 3320currently substantial differences between what GCC implements and what 3321the ISO C99 standard requires. 3322 3323To declare a function inline, use the @code{inline} keyword in its 3324declaration, like this: 3325 3326@example 3327inline int 3328inc (int *a) 3329@{ 3330 (*a)++; 3331@} 3332@end example 3333 3334(If you are writing a header file to be included in ISO C programs, write 3335@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.) 3336You can also make all ``simple enough'' functions inline with the option 3337@option{-finline-functions}. 3338 3339@opindex Winline 3340Note that certain usages in a function definition can make it unsuitable 3341for inline substitution. Among these usages are: use of varargs, use of 3342alloca, use of variable sized data types (@pxref{Variable Length}), 3343use of computed goto (@pxref{Labels as Values}), use of nonlocal goto, 3344and nested functions (@pxref{Nested Functions}). Using @option{-Winline} 3345will warn when a function marked @code{inline} could not be substituted, 3346and will give the reason for the failure. 3347 3348Note that in C and Objective-C, unlike C++, the @code{inline} keyword 3349does not affect the linkage of the function. 3350 3351@cindex automatic @code{inline} for C++ member fns 3352@cindex @code{inline} automatic for C++ member fns 3353@cindex member fns, automatically @code{inline} 3354@cindex C++ member fns, automatically @code{inline} 3355@opindex fno-default-inline 3356GCC automatically inlines member functions defined within the class 3357body of C++ programs even if they are not explicitly declared 3358@code{inline}. (You can override this with @option{-fno-default-inline}; 3359@pxref{C++ Dialect Options,,Options Controlling C++ Dialect}.) 3360 3361@cindex inline functions, omission of 3362@opindex fkeep-inline-functions 3363When a function is both inline and @code{static}, if all calls to the 3364function are integrated into the caller, and the function's address is 3365never used, then the function's own assembler code is never referenced. 3366In this case, GCC does not actually output assembler code for the 3367function, unless you specify the option @option{-fkeep-inline-functions}. 3368Some calls cannot be integrated for various reasons (in particular, 3369calls that precede the function's definition cannot be integrated, and 3370neither can recursive calls within the definition). If there is a 3371nonintegrated call, then the function is compiled to assembler code as 3372usual. The function must also be compiled as usual if the program 3373refers to its address, because that can't be inlined. 3374 3375@cindex non-static inline function 3376When an inline function is not @code{static}, then the compiler must assume 3377that there may be calls from other source files; since a global symbol can 3378be defined only once in any program, the function must not be defined in 3379the other source files, so the calls therein cannot be integrated. 3380Therefore, a non-@code{static} inline function is always compiled on its 3381own in the usual fashion. 3382 3383If you specify both @code{inline} and @code{extern} in the function 3384definition, then the definition is used only for inlining. In no case 3385is the function compiled on its own, not even if you refer to its 3386address explicitly. Such an address becomes an external reference, as 3387if you had only declared the function, and had not defined it. 3388 3389This combination of @code{inline} and @code{extern} has almost the 3390effect of a macro. The way to use it is to put a function definition in 3391a header file with these keywords, and put another copy of the 3392definition (lacking @code{inline} and @code{extern}) in a library file. 3393The definition in the header file will cause most calls to the function 3394to be inlined. If any uses of the function remain, they will refer to 3395the single copy in the library. 3396 3397For future compatibility with when GCC implements ISO C99 semantics for 3398inline functions, it is best to use @code{static inline} only. (The 3399existing semantics will remain available when @option{-std=gnu89} is 3400specified, but eventually the default will be @option{-std=gnu99} and 3401that will implement the C99 semantics, though it does not do so yet.) 3402 3403GCC does not inline any functions when not optimizing unless you specify 3404the @samp{always_inline} attribute for the function, like this: 3405 3406@example 3407/* Prototype. */ 3408inline void foo (const char) __attribute__((always_inline)); 3409@end example 3410 3411@node Extended Asm 3412@section Assembler Instructions with C Expression Operands 3413@cindex extended @code{asm} 3414@cindex @code{asm} expressions 3415@cindex assembler instructions 3416@cindex registers 3417 3418In an assembler instruction using @code{asm}, you can specify the 3419operands of the instruction using C expressions. This means you need not 3420guess which registers or memory locations will contain the data you want 3421to use. 3422 3423You must specify an assembler instruction template much like what 3424appears in a machine description, plus an operand constraint string for 3425each operand. 3426 3427For example, here is how to use the 68881's @code{fsinx} instruction: 3428 3429@example 3430asm ("fsinx %1,%0" : "=f" (result) : "f" (angle)); 3431@end example 3432 3433@noindent 3434Here @code{angle} is the C expression for the input operand while 3435@code{result} is that of the output operand. Each has @samp{"f"} as its 3436operand constraint, saying that a floating point register is required. 3437The @samp{=} in @samp{=f} indicates that the operand is an output; all 3438output operands' constraints must use @samp{=}. The constraints use the 3439same language used in the machine description (@pxref{Constraints}). 3440 3441Each operand is described by an operand-constraint string followed by 3442the C expression in parentheses. A colon separates the assembler 3443template from the first output operand and another separates the last 3444output operand from the first input, if any. Commas separate the 3445operands within each group. The total number of operands is currently 3446limited to 30; this limitation may be lifted in some future version of 3447GCC. 3448 3449If there are no output operands but there are input operands, you must 3450place two consecutive colons surrounding the place where the output 3451operands would go. 3452 3453As of GCC version 3.1, it is also possible to specify input and output 3454operands using symbolic names which can be referenced within the 3455assembler code. These names are specified inside square brackets 3456preceding the constraint string, and can be referenced inside the 3457assembler code using @code{%[@var{name}]} instead of a percentage sign 3458followed by the operand number. Using named operands the above example 3459could look like: 3460 3461@example 3462asm ("fsinx %[angle],%[output]" 3463 : [output] "=f" (result) 3464 : [angle] "f" (angle)); 3465@end example 3466 3467@noindent 3468Note that the symbolic operand names have no relation whatsoever to 3469other C identifiers. You may use any name you like, even those of 3470existing C symbols, but must ensure that no two operands within the same 3471assembler construct use the same symbolic name. 3472 3473Output operand expressions must be lvalues; the compiler can check this. 3474The input operands need not be lvalues. The compiler cannot check 3475whether the operands have data types that are reasonable for the 3476instruction being executed. It does not parse the assembler instruction 3477template and does not know what it means or even whether it is valid 3478assembler input. The extended @code{asm} feature is most often used for 3479machine instructions the compiler itself does not know exist. If 3480the output expression cannot be directly addressed (for example, it is a 3481bit-field), your constraint must allow a register. In that case, GCC 3482will use the register as the output of the @code{asm}, and then store 3483that register into the output. 3484 3485The ordinary output operands must be write-only; GCC will assume that 3486the values in these operands before the instruction are dead and need 3487not be generated. Extended asm supports input-output or read-write 3488operands. Use the constraint character @samp{+} to indicate such an 3489operand and list it with the output operands. 3490 3491When the constraints for the read-write operand (or the operand in which 3492only some of the bits are to be changed) allows a register, you may, as 3493an alternative, logically split its function into two separate operands, 3494one input operand and one write-only output operand. The connection 3495between them is expressed by constraints which say they need to be in 3496the same location when the instruction executes. You can use the same C 3497expression for both operands, or different expressions. For example, 3498here we write the (fictitious) @samp{combine} instruction with 3499@code{bar} as its read-only source operand and @code{foo} as its 3500read-write destination: 3501 3502@example 3503asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar)); 3504@end example 3505 3506@noindent 3507The constraint @samp{"0"} for operand 1 says that it must occupy the 3508same location as operand 0. A number in constraint is allowed only in 3509an input operand and it must refer to an output operand. 3510 3511Only a number in the constraint can guarantee that one operand will be in 3512the same place as another. The mere fact that @code{foo} is the value 3513of both operands is not enough to guarantee that they will be in the 3514same place in the generated assembler code. The following would not 3515work reliably: 3516 3517@example 3518asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar)); 3519@end example 3520 3521Various optimizations or reloading could cause operands 0 and 1 to be in 3522different registers; GCC knows no reason not to do so. For example, the 3523compiler might find a copy of the value of @code{foo} in one register and 3524use it for operand 1, but generate the output operand 0 in a different 3525register (copying it afterward to @code{foo}'s own address). Of course, 3526since the register for operand 1 is not even mentioned in the assembler 3527code, the result will not work, but GCC can't tell that. 3528 3529As of GCC version 3.1, one may write @code{[@var{name}]} instead of 3530the operand number for a matching constraint. For example: 3531 3532@example 3533asm ("cmoveq %1,%2,%[result]" 3534 : [result] "=r"(result) 3535 : "r" (test), "r"(new), "[result]"(old)); 3536@end example 3537 3538Some instructions clobber specific hard registers. To describe this, 3539write a third colon after the input operands, followed by the names of 3540the clobbered hard registers (given as strings). Here is a realistic 3541example for the VAX: 3542 3543@example 3544asm volatile ("movc3 %0,%1,%2" 3545 : /* no outputs */ 3546 : "g" (from), "g" (to), "g" (count) 3547 : "r0", "r1", "r2", "r3", "r4", "r5"); 3548@end example 3549 3550You may not write a clobber description in a way that overlaps with an 3551input or output operand. For example, you may not have an operand 3552describing a register class with one member if you mention that register 3553in the clobber list. There is no way for you to specify that an input 3554operand is modified without also specifying it as an output 3555operand. Note that if all the output operands you specify are for this 3556purpose (and hence unused), you will then also need to specify 3557@code{volatile} for the @code{asm} construct, as described below, to 3558prevent GCC from deleting the @code{asm} statement as unused. 3559 3560If you refer to a particular hardware register from the assembler code, 3561you will probably have to list the register after the third colon to 3562tell the compiler the register's value is modified. In some assemblers, 3563the register names begin with @samp{%}; to produce one @samp{%} in the 3564assembler code, you must write @samp{%%} in the input. 3565 3566If your assembler instruction can alter the condition code register, add 3567@samp{cc} to the list of clobbered registers. GCC on some machines 3568represents the condition codes as a specific hardware register; 3569@samp{cc} serves to name this register. On other machines, the 3570condition code is handled differently, and specifying @samp{cc} has no 3571effect. But it is valid no matter what the machine. 3572 3573If your assembler instruction modifies memory in an unpredictable 3574fashion, add @samp{memory} to the list of clobbered registers. This 3575will cause GCC to not keep memory values cached in registers across 3576the assembler instruction. You will also want to add the 3577@code{volatile} keyword if the memory affected is not listed in the 3578inputs or outputs of the @code{asm}, as the @samp{memory} clobber does 3579not count as a side-effect of the @code{asm}. 3580 3581You can put multiple assembler instructions together in a single 3582@code{asm} template, separated by the characters normally used in assembly 3583code for the system. A combination that works in most places is a newline 3584to break the line, plus a tab character to move to the instruction field 3585(written as @samp{\n\t}). Sometimes semicolons can be used, if the 3586assembler allows semicolons as a line-breaking character. Note that some 3587assembler dialects use semicolons to start a comment. 3588The input operands are guaranteed not to use any of the clobbered 3589registers, and neither will the output operands' addresses, so you can 3590read and write the clobbered registers as many times as you like. Here 3591is an example of multiple instructions in a template; it assumes the 3592subroutine @code{_foo} accepts arguments in registers 9 and 10: 3593 3594@example 3595asm ("movl %0,r9\n\tmovl %1,r10\n\tcall _foo" 3596 : /* no outputs */ 3597 : "g" (from), "g" (to) 3598 : "r9", "r10"); 3599@end example 3600 3601Unless an output operand has the @samp{&} constraint modifier, GCC 3602may allocate it in the same register as an unrelated input operand, on 3603the assumption the inputs are consumed before the outputs are produced. 3604This assumption may be false if the assembler code actually consists of 3605more than one instruction. In such a case, use @samp{&} for each output 3606operand that may not overlap an input. @xref{Modifiers}. 3607 3608If you want to test the condition code produced by an assembler 3609instruction, you must include a branch and a label in the @code{asm} 3610construct, as follows: 3611 3612@example 3613asm ("clr %0\n\tfrob %1\n\tbeq 0f\n\tmov #1,%0\n0:" 3614 : "g" (result) 3615 : "g" (input)); 3616@end example 3617 3618@noindent 3619This assumes your assembler supports local labels, as the GNU assembler 3620and most Unix assemblers do. 3621 3622Speaking of labels, jumps from one @code{asm} to another are not 3623supported. The compiler's optimizers do not know about these jumps, and 3624therefore they cannot take account of them when deciding how to 3625optimize. 3626 3627@cindex macros containing @code{asm} 3628Usually the most convenient way to use these @code{asm} instructions is to 3629encapsulate them in macros that look like functions. For example, 3630 3631@example 3632#define sin(x) \ 3633(@{ double __value, __arg = (x); \ 3634 asm ("fsinx %1,%0": "=f" (__value): "f" (__arg)); \ 3635 __value; @}) 3636@end example 3637 3638@noindent 3639Here the variable @code{__arg} is used to make sure that the instruction 3640operates on a proper @code{double} value, and to accept only those 3641arguments @code{x} which can convert automatically to a @code{double}. 3642 3643Another way to make sure the instruction operates on the correct data 3644type is to use a cast in the @code{asm}. This is different from using a 3645variable @code{__arg} in that it converts more different types. For 3646example, if the desired type were @code{int}, casting the argument to 3647@code{int} would accept a pointer with no complaint, while assigning the 3648argument to an @code{int} variable named @code{__arg} would warn about 3649using a pointer unless the caller explicitly casts it. 3650 3651If an @code{asm} has output operands, GCC assumes for optimization 3652purposes the instruction has no side effects except to change the output 3653operands. This does not mean instructions with a side effect cannot be 3654used, but you must be careful, because the compiler may eliminate them 3655if the output operands aren't used, or move them out of loops, or 3656replace two with one if they constitute a common subexpression. Also, 3657if your instruction does have a side effect on a variable that otherwise 3658appears not to change, the old value of the variable may be reused later 3659if it happens to be found in a register. 3660 3661You can prevent an @code{asm} instruction from being deleted, moved 3662significantly, or combined, by writing the keyword @code{volatile} after 3663the @code{asm}. For example: 3664 3665@example 3666#define get_and_set_priority(new) \ 3667(@{ int __old; \ 3668 asm volatile ("get_and_set_priority %0, %1" \ 3669 : "=g" (__old) : "g" (new)); \ 3670 __old; @}) 3671@end example 3672 3673@noindent 3674If you write an @code{asm} instruction with no outputs, GCC will know 3675the instruction has side-effects and will not delete the instruction or 3676move it outside of loops. 3677 3678The @code{volatile} keyword indicates that the instruction has 3679important side-effects. GCC will not delete a volatile @code{asm} if 3680it is reachable. (The instruction can still be deleted if GCC can 3681prove that control-flow will never reach the location of the 3682instruction.) In addition, GCC will not reschedule instructions 3683across a volatile @code{asm} instruction. For example: 3684 3685@example 3686*(volatile int *)addr = foo; 3687asm volatile ("eieio" : : ); 3688@end example 3689 3690@noindent 3691Assume @code{addr} contains the address of a memory mapped device 3692register. The PowerPC @code{eieio} instruction (Enforce In-order 3693Execution of I/O) tells the CPU to make sure that the store to that 3694device register happens before it issues any other I/O@. 3695 3696Note that even a volatile @code{asm} instruction can be moved in ways 3697that appear insignificant to the compiler, such as across jump 3698instructions. You can't expect a sequence of volatile @code{asm} 3699instructions to remain perfectly consecutive. If you want consecutive 3700output, use a single @code{asm}. Also, GCC will perform some 3701optimizations across a volatile @code{asm} instruction; GCC does not 3702``forget everything'' when it encounters a volatile @code{asm} 3703instruction the way some other compilers do. 3704 3705An @code{asm} instruction without any operands or clobbers (an ``old 3706style'' @code{asm}) will be treated identically to a volatile 3707@code{asm} instruction. 3708 3709It is a natural idea to look for a way to give access to the condition 3710code left by the assembler instruction. However, when we attempted to 3711implement this, we found no way to make it work reliably. The problem 3712is that output operands might need reloading, which would result in 3713additional following ``store'' instructions. On most machines, these 3714instructions would alter the condition code before there was time to 3715test it. This problem doesn't arise for ordinary ``test'' and 3716``compare'' instructions because they don't have any output operands. 3717 3718For reasons similar to those described above, it is not possible to give 3719an assembler instruction access to the condition code left by previous 3720instructions. 3721 3722If you are writing a header file that should be includable in ISO C 3723programs, write @code{__asm__} instead of @code{asm}. @xref{Alternate 3724Keywords}. 3725 3726@subsection i386 floating point asm operands 3727 3728There are several rules on the usage of stack-like regs in 3729asm_operands insns. These rules apply only to the operands that are 3730stack-like regs: 3731 3732@enumerate 3733@item 3734Given a set of input regs that die in an asm_operands, it is 3735necessary to know which are implicitly popped by the asm, and 3736which must be explicitly popped by gcc. 3737 3738An input reg that is implicitly popped by the asm must be 3739explicitly clobbered, unless it is constrained to match an 3740output operand. 3741 3742@item 3743For any input reg that is implicitly popped by an asm, it is 3744necessary to know how to adjust the stack to compensate for the pop. 3745If any non-popped input is closer to the top of the reg-stack than 3746the implicitly popped reg, it would not be possible to know what the 3747stack looked like---it's not clear how the rest of the stack ``slides 3748up''. 3749 3750All implicitly popped input regs must be closer to the top of 3751the reg-stack than any input that is not implicitly popped. 3752 3753It is possible that if an input dies in an insn, reload might 3754use the input reg for an output reload. Consider this example: 3755 3756@example 3757asm ("foo" : "=t" (a) : "f" (b)); 3758@end example 3759 3760This asm says that input B is not popped by the asm, and that 3761the asm pushes a result onto the reg-stack, i.e., the stack is one 3762deeper after the asm than it was before. But, it is possible that 3763reload will think that it can use the same reg for both the input and 3764the output, if input B dies in this insn. 3765 3766If any input operand uses the @code{f} constraint, all output reg 3767constraints must use the @code{&} earlyclobber. 3768 3769The asm above would be written as 3770 3771@example 3772asm ("foo" : "=&t" (a) : "f" (b)); 3773@end example 3774 3775@item 3776Some operands need to be in particular places on the stack. All 3777output operands fall in this category---there is no other way to 3778know which regs the outputs appear in unless the user indicates 3779this in the constraints. 3780 3781Output operands must specifically indicate which reg an output 3782appears in after an asm. @code{=f} is not allowed: the operand 3783constraints must select a class with a single reg. 3784 3785@item 3786Output operands may not be ``inserted'' between existing stack regs. 3787Since no 387 opcode uses a read/write operand, all output operands 3788are dead before the asm_operands, and are pushed by the asm_operands. 3789It makes no sense to push anywhere but the top of the reg-stack. 3790 3791Output operands must start at the top of the reg-stack: output 3792operands may not ``skip'' a reg. 3793 3794@item 3795Some asm statements may need extra stack space for internal 3796calculations. This can be guaranteed by clobbering stack registers 3797unrelated to the inputs and outputs. 3798 3799@end enumerate 3800 3801Here are a couple of reasonable asms to want to write. This asm 3802takes one input, which is internally popped, and produces two outputs. 3803 3804@example 3805asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp)); 3806@end example 3807 3808This asm takes two inputs, which are popped by the @code{fyl2xp1} opcode, 3809and replaces them with one output. The user must code the @code{st(1)} 3810clobber for reg-stack.c to know that @code{fyl2xp1} pops both inputs. 3811 3812@example 3813asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)"); 3814@end example 3815 3816@include md.texi 3817 3818@node Asm Labels 3819@section Controlling Names Used in Assembler Code 3820@cindex assembler names for identifiers 3821@cindex names used in assembler code 3822@cindex identifiers, names in assembler code 3823 3824You can specify the name to be used in the assembler code for a C 3825function or variable by writing the @code{asm} (or @code{__asm__}) 3826keyword after the declarator as follows: 3827 3828@example 3829int foo asm ("myfoo") = 2; 3830@end example 3831 3832@noindent 3833This specifies that the name to be used for the variable @code{foo} in 3834the assembler code should be @samp{myfoo} rather than the usual 3835@samp{_foo}. 3836 3837On systems where an underscore is normally prepended to the name of a C 3838function or variable, this feature allows you to define names for the 3839linker that do not start with an underscore. 3840 3841It does not make sense to use this feature with a non-static local 3842variable since such variables do not have assembler names. If you are 3843trying to put the variable in a particular register, see @ref{Explicit 3844Reg Vars}. GCC presently accepts such code with a warning, but will 3845probably be changed to issue an error, rather than a warning, in the 3846future. 3847 3848You cannot use @code{asm} in this way in a function @emph{definition}; but 3849you can get the same effect by writing a declaration for the function 3850before its definition and putting @code{asm} there, like this: 3851 3852@example 3853extern func () asm ("FUNC"); 3854 3855func (x, y) 3856 int x, y; 3857@dots{} 3858@end example 3859 3860It is up to you to make sure that the assembler names you choose do not 3861conflict with any other assembler symbols. Also, you must not use a 3862register name; that would produce completely invalid assembler code. GCC 3863does not as yet have the ability to store static variables in registers. 3864Perhaps that will be added. 3865 3866@node Explicit Reg Vars 3867@section Variables in Specified Registers 3868@cindex explicit register variables 3869@cindex variables in specified registers 3870@cindex specified registers 3871@cindex registers, global allocation 3872 3873GNU C allows you to put a few global variables into specified hardware 3874registers. You can also specify the register in which an ordinary 3875register variable should be allocated. 3876 3877@itemize @bullet 3878@item 3879Global register variables reserve registers throughout the program. 3880This may be useful in programs such as programming language 3881interpreters which have a couple of global variables that are accessed 3882very often. 3883 3884@item 3885Local register variables in specific registers do not reserve the 3886registers. The compiler's data flow analysis is capable of determining 3887where the specified registers contain live values, and where they are 3888available for other uses. Stores into local register variables may be deleted 3889when they appear to be dead according to dataflow analysis. References 3890to local register variables may be deleted or moved or simplified. 3891 3892These local variables are sometimes convenient for use with the extended 3893@code{asm} feature (@pxref{Extended Asm}), if you want to write one 3894output of the assembler instruction directly into a particular register. 3895(This will work provided the register you specify fits the constraints 3896specified for that operand in the @code{asm}.) 3897@end itemize 3898 3899@menu 3900* Global Reg Vars:: 3901* Local Reg Vars:: 3902@end menu 3903 3904@node Global Reg Vars 3905@subsection Defining Global Register Variables 3906@cindex global register variables 3907@cindex registers, global variables in 3908 3909You can define a global register variable in GNU C like this: 3910 3911@example 3912register int *foo asm ("a5"); 3913@end example 3914 3915@noindent 3916Here @code{a5} is the name of the register which should be used. Choose a 3917register which is normally saved and restored by function calls on your 3918machine, so that library routines will not clobber it. 3919 3920Naturally the register name is cpu-dependent, so you would need to 3921conditionalize your program according to cpu type. The register 3922@code{a5} would be a good choice on a 68000 for a variable of pointer 3923type. On machines with register windows, be sure to choose a ``global'' 3924register that is not affected magically by the function call mechanism. 3925 3926In addition, operating systems on one type of cpu may differ in how they 3927name the registers; then you would need additional conditionals. For 3928example, some 68000 operating systems call this register @code{%a5}. 3929 3930Eventually there may be a way of asking the compiler to choose a register 3931automatically, but first we need to figure out how it should choose and 3932how to enable you to guide the choice. No solution is evident. 3933 3934Defining a global register variable in a certain register reserves that 3935register entirely for this use, at least within the current compilation. 3936The register will not be allocated for any other purpose in the functions 3937in the current compilation. The register will not be saved and restored by 3938these functions. Stores into this register are never deleted even if they 3939would appear to be dead, but references may be deleted or moved or 3940simplified. 3941 3942It is not safe to access the global register variables from signal 3943handlers, or from more than one thread of control, because the system 3944library routines may temporarily use the register for other things (unless 3945you recompile them specially for the task at hand). 3946 3947@cindex @code{qsort}, and global register variables 3948It is not safe for one function that uses a global register variable to 3949call another such function @code{foo} by way of a third function 3950@code{lose} that was compiled without knowledge of this variable (i.e.@: in a 3951different source file in which the variable wasn't declared). This is 3952because @code{lose} might save the register and put some other value there. 3953For example, you can't expect a global register variable to be available in 3954the comparison-function that you pass to @code{qsort}, since @code{qsort} 3955might have put something else in that register. (If you are prepared to 3956recompile @code{qsort} with the same global register variable, you can 3957solve this problem.) 3958 3959If you want to recompile @code{qsort} or other source files which do not 3960actually use your global register variable, so that they will not use that 3961register for any other purpose, then it suffices to specify the compiler 3962option @option{-ffixed-@var{reg}}. You need not actually add a global 3963register declaration to their source code. 3964 3965A function which can alter the value of a global register variable cannot 3966safely be called from a function compiled without this variable, because it 3967could clobber the value the caller expects to find there on return. 3968Therefore, the function which is the entry point into the part of the 3969program that uses the global register variable must explicitly save and 3970restore the value which belongs to its caller. 3971 3972@cindex register variable after @code{longjmp} 3973@cindex global register after @code{longjmp} 3974@cindex value after @code{longjmp} 3975@findex longjmp 3976@findex setjmp 3977On most machines, @code{longjmp} will restore to each global register 3978variable the value it had at the time of the @code{setjmp}. On some 3979machines, however, @code{longjmp} will not change the value of global 3980register variables. To be portable, the function that called @code{setjmp} 3981should make other arrangements to save the values of the global register 3982variables, and to restore them in a @code{longjmp}. This way, the same 3983thing will happen regardless of what @code{longjmp} does. 3984 3985All global register variable declarations must precede all function 3986definitions. If such a declaration could appear after function 3987definitions, the declaration would be too late to prevent the register from 3988being used for other purposes in the preceding functions. 3989 3990Global register variables may not have initial values, because an 3991executable file has no means to supply initial contents for a register. 3992 3993On the Sparc, there are reports that g3 @dots{} g7 are suitable 3994registers, but certain library functions, such as @code{getwd}, as well 3995as the subroutines for division and remainder, modify g3 and g4. g1 and 3996g2 are local temporaries. 3997 3998On the 68000, a2 @dots{} a5 should be suitable, as should d2 @dots{} d7. 3999Of course, it will not do to use more than a few of those. 4000 4001@node Local Reg Vars 4002@subsection Specifying Registers for Local Variables 4003@cindex local variables, specifying registers 4004@cindex specifying registers for local variables 4005@cindex registers for local variables 4006 4007You can define a local register variable with a specified register 4008like this: 4009 4010@example 4011register int *foo asm ("a5"); 4012@end example 4013 4014@noindent 4015Here @code{a5} is the name of the register which should be used. Note 4016that this is the same syntax used for defining global register 4017variables, but for a local variable it would appear within a function. 4018 4019Naturally the register name is cpu-dependent, but this is not a 4020problem, since specific registers are most often useful with explicit 4021assembler instructions (@pxref{Extended Asm}). Both of these things 4022generally require that you conditionalize your program according to 4023cpu type. 4024 4025In addition, operating systems on one type of cpu may differ in how they 4026name the registers; then you would need additional conditionals. For 4027example, some 68000 operating systems call this register @code{%a5}. 4028 4029Defining such a register variable does not reserve the register; it 4030remains available for other uses in places where flow control determines 4031the variable's value is not live. However, these registers are made 4032unavailable for use in the reload pass; excessive use of this feature 4033leaves the compiler too few available registers to compile certain 4034functions. 4035 4036This option does not guarantee that GCC will generate code that has 4037this variable in the register you specify at all times. You may not 4038code an explicit reference to this register in an @code{asm} statement 4039and assume it will always refer to this variable. 4040 4041Stores into local register variables may be deleted when they appear to be dead 4042according to dataflow analysis. References to local register variables may 4043be deleted or moved or simplified. 4044 4045@node Alternate Keywords 4046@section Alternate Keywords 4047@cindex alternate keywords 4048@cindex keywords, alternate 4049 4050The option @option{-traditional} disables certain keywords; 4051@option{-ansi} and the various @option{-std} options disable certain 4052others. This causes trouble when you want to use GNU C extensions, or 4053ISO C features, in a general-purpose header file that should be usable 4054by all programs, including ISO C programs and traditional ones. The 4055keywords @code{asm}, @code{typeof} and @code{inline} cannot be used 4056since they won't work in a program compiled with @option{-ansi} 4057(although @code{inline} can be used in a program compiled with 4058@option{-std=c99}), while the keywords @code{const}, @code{volatile}, 4059@code{signed}, @code{typeof} and @code{inline} won't work in a program 4060compiled with @option{-traditional}. The ISO C99 keyword 4061@code{restrict} is only available when @option{-std=gnu99} (which will 4062eventually be the default) or @option{-std=c99} (or the equivalent 4063@option{-std=iso9899:1999}) is used. 4064 4065The way to solve these problems is to put @samp{__} at the beginning and 4066end of each problematical keyword. For example, use @code{__asm__} 4067instead of @code{asm}, @code{__const__} instead of @code{const}, and 4068@code{__inline__} instead of @code{inline}. 4069 4070Other C compilers won't accept these alternative keywords; if you want to 4071compile with another compiler, you can define the alternate keywords as 4072macros to replace them with the customary keywords. It looks like this: 4073 4074@example 4075#ifndef __GNUC__ 4076#define __asm__ asm 4077#endif 4078@end example 4079 4080@findex __extension__ 4081@opindex pedantic 4082@option{-pedantic} and other options cause warnings for many GNU C extensions. 4083You can 4084prevent such warnings within one expression by writing 4085@code{__extension__} before the expression. @code{__extension__} has no 4086effect aside from this. 4087 4088@node Incomplete Enums 4089@section Incomplete @code{enum} Types 4090 4091You can define an @code{enum} tag without specifying its possible values. 4092This results in an incomplete type, much like what you get if you write 4093@code{struct foo} without describing the elements. A later declaration 4094which does specify the possible values completes the type. 4095 4096You can't allocate variables or storage using the type while it is 4097incomplete. However, you can work with pointers to that type. 4098 4099This extension may not be very useful, but it makes the handling of 4100@code{enum} more consistent with the way @code{struct} and @code{union} 4101are handled. 4102 4103This extension is not supported by GNU C++. 4104 4105@node Function Names 4106@section Function Names as Strings 4107@cindex @code{__FUNCTION__} identifier 4108@cindex @code{__PRETTY_FUNCTION__} identifier 4109@cindex @code{__func__} identifier 4110 4111GCC predefines two magic identifiers to hold the name of the current 4112function. The identifier @code{__FUNCTION__} holds the name of the function 4113as it appears in the source. The identifier @code{__PRETTY_FUNCTION__} 4114holds the name of the function pretty printed in a language specific 4115fashion. 4116 4117These names are always the same in a C function, but in a C++ function 4118they may be different. For example, this program: 4119 4120@smallexample 4121extern "C" @{ 4122extern int printf (char *, ...); 4123@} 4124 4125class a @{ 4126 public: 4127 sub (int i) 4128 @{ 4129 printf ("__FUNCTION__ = %s\n", __FUNCTION__); 4130 printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__); 4131 @} 4132@}; 4133 4134int 4135main (void) 4136@{ 4137 a ax; 4138 ax.sub (0); 4139 return 0; 4140@} 4141@end smallexample 4142 4143@noindent 4144gives this output: 4145 4146@smallexample 4147__FUNCTION__ = sub 4148__PRETTY_FUNCTION__ = int a::sub (int) 4149@end smallexample 4150 4151The compiler automagically replaces the identifiers with a string 4152literal containing the appropriate name. Thus, they are neither 4153preprocessor macros, like @code{__FILE__} and @code{__LINE__}, nor 4154variables. This means that they catenate with other string literals, and 4155that they can be used to initialize char arrays. For example 4156 4157@smallexample 4158char here[] = "Function " __FUNCTION__ " in " __FILE__; 4159@end smallexample 4160 4161On the other hand, @samp{#ifdef __FUNCTION__} does not have any special 4162meaning inside a function, since the preprocessor does not do anything 4163special with the identifier @code{__FUNCTION__}. 4164 4165Note that these semantics are deprecated, and that GCC 3.2 will handle 4166@code{__FUNCTION__} and @code{__PRETTY_FUNCTION__} the same way as 4167@code{__func__}. @code{__func__} is defined by the ISO standard C99: 4168 4169@display 4170The identifier @code{__func__} is implicitly declared by the translator 4171as if, immediately following the opening brace of each function 4172definition, the declaration 4173 4174@smallexample 4175static const char __func__[] = "function-name"; 4176@end smallexample 4177 4178appeared, where function-name is the name of the lexically-enclosing 4179function. This name is the unadorned name of the function. 4180@end display 4181 4182By this definition, @code{__func__} is a variable, not a string literal. 4183In particular, @code{__func__} does not catenate with other string 4184literals. 4185 4186In @code{C++}, @code{__FUNCTION__} and @code{__PRETTY_FUNCTION__} are 4187variables, declared in the same way as @code{__func__}. 4188 4189@node Return Address 4190@section Getting the Return or Frame Address of a Function 4191 4192These functions may be used to get information about the callers of a 4193function. 4194 4195@deftypefn {Built-in Function} {void *} __builtin_return_address (unsigned int @var{level}) 4196This function returns the return address of the current function, or of 4197one of its callers. The @var{level} argument is number of frames to 4198scan up the call stack. A value of @code{0} yields the return address 4199of the current function, a value of @code{1} yields the return address 4200of the caller of the current function, and so forth. 4201 4202The @var{level} argument must be a constant integer. 4203 4204On some machines it may be impossible to determine the return address of 4205any function other than the current one; in such cases, or when the top 4206of the stack has been reached, this function will return @code{0} or a 4207random value. In addition, @code{__builtin_frame_address} may be used 4208to determine if the top of the stack has been reached. 4209 4210This function should only be used with a nonzero argument for debugging 4211purposes. 4212@end deftypefn 4213 4214@deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level}) 4215This function is similar to @code{__builtin_return_address}, but it 4216returns the address of the function frame rather than the return address 4217of the function. Calling @code{__builtin_frame_address} with a value of 4218@code{0} yields the frame address of the current function, a value of 4219@code{1} yields the frame address of the caller of the current function, 4220and so forth. 4221 4222The frame is the area on the stack which holds local variables and saved 4223registers. The frame address is normally the address of the first word 4224pushed on to the stack by the function. However, the exact definition 4225depends upon the processor and the calling convention. If the processor 4226has a dedicated frame pointer register, and the function has a frame, 4227then @code{__builtin_frame_address} will return the value of the frame 4228pointer register. 4229 4230On some machines it may be impossible to determine the frame address of 4231any function other than the current one; in such cases, or when the top 4232of the stack has been reached, this function will return @code{0} if 4233the first frame pointer is properly initialized by the startup code. 4234 4235This function should only be used with a nonzero argument for debugging 4236purposes. 4237@end deftypefn 4238 4239@node Vector Extensions 4240@section Using vector instructions through built-in functions 4241 4242On some targets, the instruction set contains SIMD vector instructions that 4243operate on multiple values contained in one large register at the same time. 4244For example, on the i386 the MMX, 3Dnow! and SSE extensions can be used 4245this way. 4246 4247The first step in using these extensions is to provide the necessary data 4248types. This should be done using an appropriate @code{typedef}: 4249 4250@example 4251typedef int v4si __attribute__ ((mode(V4SI))); 4252@end example 4253 4254The base type @code{int} is effectively ignored by the compiler, the 4255actual properties of the new type @code{v4si} are defined by the 4256@code{__attribute__}. It defines the machine mode to be used; for vector 4257types these have the form @code{V@var{n}@var{B}}; @var{n} should be the 4258number of elements in the vector, and @var{B} should be the base mode of the 4259individual elements. The following can be used as base modes: 4260 4261@table @code 4262@item QI 4263An integer that is as wide as the smallest addressable unit, usually 8 bits. 4264@item HI 4265An integer, twice as wide as a QI mode integer, usually 16 bits. 4266@item SI 4267An integer, four times as wide as a QI mode integer, usually 32 bits. 4268@item DI 4269An integer, eight times as wide as a QI mode integer, usually 64 bits. 4270@item SF 4271A floating point value, as wide as a SI mode integer, usually 32 bits. 4272@item DF 4273A floating point value, as wide as a DI mode integer, usually 64 bits. 4274@end table 4275 4276Not all base types or combinations are always valid; which modes can be used 4277is determined by the target machine. For example, if targetting the i386 MMX 4278extensions, only @code{V8QI}, @code{V4HI} and @code{V2SI} are allowed modes. 4279 4280There are no @code{V1xx} vector modes - they would be identical to the 4281corresponding base mode. 4282 4283There is no distinction between signed and unsigned vector modes. This 4284distinction is made by the operations that perform on the vectors, not 4285by the data type. 4286 4287The types defined in this manner are somewhat special, they cannot be 4288used with most normal C operations (i.e., a vector addition can @emph{not} 4289be represented by a normal addition of two vector type variables). You 4290can declare only variables and use them in function calls and returns, as 4291well as in assignments and some casts. It is possible to cast from one 4292vector type to another, provided they are of the same size (in fact, you 4293can also cast vectors to and from other datatypes of the same size). 4294 4295A port that supports vector operations provides a set of built-in functions 4296that can be used to operate on vectors. For example, a function to add two 4297vectors and multiply the result by a third could look like this: 4298 4299@example 4300v4si f (v4si a, v4si b, v4si c) 4301@{ 4302 v4si tmp = __builtin_addv4si (a, b); 4303 return __builtin_mulv4si (tmp, c); 4304@} 4305 4306@end example 4307 4308@node Other Builtins 4309@section Other built-in functions provided by GCC 4310@cindex built-in functions 4311@findex __builtin_isgreater 4312@findex __builtin_isgreaterequal 4313@findex __builtin_isless 4314@findex __builtin_islessequal 4315@findex __builtin_islessgreater 4316@findex __builtin_isunordered 4317@findex abort 4318@findex abs 4319@findex alloca 4320@findex bcmp 4321@findex bzero 4322@findex cimag 4323@findex cimagf 4324@findex cimagl 4325@findex conj 4326@findex conjf 4327@findex conjl 4328@findex cos 4329@findex cosf 4330@findex cosl 4331@findex creal 4332@findex crealf 4333@findex creall 4334@findex exit 4335@findex _exit 4336@findex _Exit 4337@findex fabs 4338@findex fabsf 4339@findex fabsl 4340@findex ffs 4341@findex fprintf 4342@findex fprintf_unlocked 4343@findex fputs 4344@findex fputs_unlocked 4345@findex imaxabs 4346@findex index 4347@findex labs 4348@findex llabs 4349@findex memcmp 4350@findex memcpy 4351@findex memset 4352@findex printf 4353@findex printf_unlocked 4354@findex rindex 4355@findex sin 4356@findex sinf 4357@findex sinl 4358@findex sqrt 4359@findex sqrtf 4360@findex sqrtl 4361@findex strcat 4362@findex strchr 4363@findex strcmp 4364@findex strcpy 4365@findex strcspn 4366@findex strlen 4367@findex strncat 4368@findex strncmp 4369@findex strncpy 4370@findex strpbrk 4371@findex strrchr 4372@findex strspn 4373@findex strstr 4374 4375GCC provides a large number of built-in functions other than the ones 4376mentioned above. Some of these are for internal use in the processing 4377of exceptions or variable-length argument lists and will not be 4378documented here because they may change from time to time; we do not 4379recommend general use of these functions. 4380 4381The remaining functions are provided for optimization purposes. 4382 4383@opindex fno-builtin 4384GCC includes built-in versions of many of the functions in the standard 4385C library. The versions prefixed with @code{__builtin_} will always be 4386treated as having the same meaning as the C library function even if you 4387specify the @option{-fno-builtin} option. (@pxref{C Dialect Options}) 4388Many of these functions are only optimized in certain cases; if they are 4389not optimized in a particular case, a call to the library function will 4390be emitted. 4391 4392@opindex ansi 4393@opindex std 4394The functions @code{abort}, @code{exit}, @code{_Exit} and @code{_exit} 4395are recognized and presumed not to return, but otherwise are not built 4396in. @code{_exit} is not recognized in strict ISO C mode (@option{-ansi}, 4397@option{-std=c89} or @option{-std=c99}). @code{_Exit} is not recognized in 4398strict C89 mode (@option{-ansi} or @option{-std=c89}). 4399 4400Outside strict ISO C mode, the functions @code{alloca}, @code{bcmp}, 4401@code{bzero}, @code{index}, @code{rindex}, @code{ffs}, @code{fputs_unlocked}, 4402@code{printf_unlocked} and @code{fprintf_unlocked} may be handled as 4403built-in functions. All these functions have corresponding versions 4404prefixed with @code{__builtin_}, which may be used even in strict C89 4405mode. 4406 4407The ISO C99 functions @code{conj}, @code{conjf}, @code{conjl}, 4408@code{creal}, @code{crealf}, @code{creall}, @code{cimag}, @code{cimagf}, 4409@code{cimagl}, @code{llabs} and @code{imaxabs} are handled as built-in 4410functions except in strict ISO C89 mode. There are also built-in 4411versions of the ISO C99 functions @code{cosf}, @code{cosl}, 4412@code{fabsf}, @code{fabsl}, @code{sinf}, @code{sinl}, @code{sqrtf}, and 4413@code{sqrtl}, that are recognized in any mode since ISO C89 reserves 4414these names for the purpose to which ISO C99 puts them. All these 4415functions have corresponding versions prefixed with @code{__builtin_}. 4416 4417The ISO C89 functions @code{abs}, @code{cos}, @code{fabs}, 4418@code{fprintf}, @code{fputs}, @code{labs}, @code{memcmp}, @code{memcpy}, 4419@code{memset}, @code{printf}, @code{sin}, @code{sqrt}, @code{strcat}, 4420@code{strchr}, @code{strcmp}, @code{strcpy}, @code{strcspn}, 4421@code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy}, 4422@code{strpbrk}, @code{strrchr}, @code{strspn}, and @code{strstr} are all 4423recognized as built-in functions unless @option{-fno-builtin} is 4424specified (or @option{-fno-builtin-@var{function}} is specified for an 4425individual function). All of these functions have corresponding 4426versions prefixed with @code{__builtin_}. 4427 4428GCC provides built-in versions of the ISO C99 floating point comparison 4429macros that avoid raising exceptions for unordered operands. They have 4430the same names as the standard macros ( @code{isgreater}, 4431@code{isgreaterequal}, @code{isless}, @code{islessequal}, 4432@code{islessgreater}, and @code{isunordered}) , with @code{__builtin_} 4433prefixed. We intend for a library implementor to be able to simply 4434@code{#define} each standard macro to its built-in equivalent. 4435 4436@deftypefn {Built-in Function} int __builtin_types_compatible_p (@var{type1}, @var{type2}) 4437 4438You can use the built-in function @code{__builtin_types_compatible_p} to 4439determine whether two types are the same. 4440 4441This built-in function returns 1 if the unqualified versions of the 4442types @var{type1} and @var{type2} (which are types, not expressions) are 4443compatible, 0 otherwise. The result of this built-in function can be 4444used in integer constant expressions. 4445 4446This built-in function ignores top level qualifiers (e.g., @code{const}, 4447@code{volatile}). For example, @code{int} is equivalent to @code{const 4448int}. 4449 4450The type @code{int[]} and @code{int[5]} are compatible. On the other 4451hand, @code{int} and @code{char *} are not compatible, even if the size 4452of their types, on the particular architecture are the same. Also, the 4453amount of pointer indirection is taken into account when determining 4454similarity. Consequently, @code{short *} is not similar to 4455@code{short **}. Furthermore, two types that are typedefed are 4456considered compatible if their underlying types are compatible. 4457 4458An @code{enum} type is considered to be compatible with another 4459@code{enum} type. For example, @code{enum @{foo, bar@}} is similar to 4460@code{enum @{hot, dog@}}. 4461 4462You would typically use this function in code whose execution varies 4463depending on the arguments' types. For example: 4464 4465@smallexample 4466#define foo(x) \ 4467 (@{ \ 4468 typeof (x) tmp; \ 4469 if (__builtin_types_compatible_p (typeof (x), long double)) \ 4470 tmp = foo_long_double (tmp); \ 4471 else if (__builtin_types_compatible_p (typeof (x), double)) \ 4472 tmp = foo_double (tmp); \ 4473 else if (__builtin_types_compatible_p (typeof (x), float)) \ 4474 tmp = foo_float (tmp); \ 4475 else \ 4476 abort (); \ 4477 tmp; \ 4478 @}) 4479@end smallexample 4480 4481@emph{Note:} This construct is only available for C. 4482 4483@end deftypefn 4484 4485@deftypefn {Built-in Function} @var{type} __builtin_choose_expr (@var{const_exp}, @var{exp1}, @var{exp2}) 4486 4487You can use the built-in function @code{__builtin_choose_expr} to 4488evaluate code depending on the value of a constant expression. This 4489built-in function returns @var{exp1} if @var{const_exp}, which is a 4490constant expression that must be able to be determined at compile time, 4491is nonzero. Otherwise it returns 0. 4492 4493This built-in function is analogous to the @samp{? :} operator in C, 4494except that the expression returned has its type unaltered by promotion 4495rules. Also, the built-in function does not evaluate the expression 4496that was not chosen. For example, if @var{const_exp} evaluates to true, 4497@var{exp2} is not evaluated even if it has side-effects. 4498 4499This built-in function can return an lvalue if the chosen argument is an 4500lvalue. 4501 4502If @var{exp1} is returned, the return type is the same as @var{exp1}'s 4503type. Similarly, if @var{exp2} is returned, its return type is the same 4504as @var{exp2}. 4505 4506Example: 4507 4508@smallexample 4509#define foo(x) \ 4510 __builtin_choose_expr (__builtin_types_compatible_p (typeof (x), double), \ 4511 foo_double (x), \ 4512 __builtin_choose_expr (__builtin_types_compatible_p (typeof (x), float), \ 4513 foo_float (x), \ 4514 /* @r{The void expression results in a compile-time error} \ 4515 @r{when assigning the result to something.} */ \ 4516 (void)0)) 4517@end smallexample 4518 4519@emph{Note:} This construct is only available for C. Furthermore, the 4520unused expression (@var{exp1} or @var{exp2} depending on the value of 4521@var{const_exp}) may still generate syntax errors. This may change in 4522future revisions. 4523 4524@end deftypefn 4525 4526@deftypefn {Built-in Function} int __builtin_constant_p (@var{exp}) 4527You can use the built-in function @code{__builtin_constant_p} to 4528determine if a value is known to be constant at compile-time and hence 4529that GCC can perform constant-folding on expressions involving that 4530value. The argument of the function is the value to test. The function 4531returns the integer 1 if the argument is known to be a compile-time 4532constant and 0 if it is not known to be a compile-time constant. A 4533return of 0 does not indicate that the value is @emph{not} a constant, 4534but merely that GCC cannot prove it is a constant with the specified 4535value of the @option{-O} option. 4536 4537You would typically use this function in an embedded application where 4538memory was a critical resource. If you have some complex calculation, 4539you may want it to be folded if it involves constants, but need to call 4540a function if it does not. For example: 4541 4542@smallexample 4543#define Scale_Value(X) \ 4544 (__builtin_constant_p (X) \ 4545 ? ((X) * SCALE + OFFSET) : Scale (X)) 4546@end smallexample 4547 4548You may use this built-in function in either a macro or an inline 4549function. However, if you use it in an inlined function and pass an 4550argument of the function as the argument to the built-in, GCC will 4551never return 1 when you call the inline function with a string constant 4552or compound literal (@pxref{Compound Literals}) and will not return 1 4553when you pass a constant numeric value to the inline function unless you 4554specify the @option{-O} option. 4555 4556You may also use @code{__builtin_constant_p} in initializers for static 4557data. For instance, you can write 4558 4559@smallexample 4560static const int table[] = @{ 4561 __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1, 4562 /* ... */ 4563@}; 4564@end smallexample 4565 4566@noindent 4567This is an acceptable initializer even if @var{EXPRESSION} is not a 4568constant expression. GCC must be more conservative about evaluating the 4569built-in in this case, because it has no opportunity to perform 4570optimization. 4571 4572Previous versions of GCC did not accept this built-in in data 4573initializers. The earliest version where it is completely safe is 45743.0.1. 4575@end deftypefn 4576 4577@deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c}) 4578@opindex fprofile-arcs 4579You may use @code{__builtin_expect} to provide the compiler with 4580branch prediction information. In general, you should prefer to 4581use actual profile feedback for this (@option{-fprofile-arcs}), as 4582programmers are notoriously bad at predicting how their programs 4583actually perform. However, there are applications in which this 4584data is hard to collect. 4585 4586The return value is the value of @var{exp}, which should be an 4587integral expression. The value of @var{c} must be a compile-time 4588constant. The semantics of the built-in are that it is expected 4589that @var{exp} == @var{c}. For example: 4590 4591@smallexample 4592if (__builtin_expect (x, 0)) 4593 foo (); 4594@end smallexample 4595 4596@noindent 4597would indicate that we do not expect to call @code{foo}, since 4598we expect @code{x} to be zero. Since you are limited to integral 4599expressions for @var{exp}, you should use constructions such as 4600 4601@smallexample 4602if (__builtin_expect (ptr != NULL, 1)) 4603 error (); 4604@end smallexample 4605 4606@noindent 4607when testing pointer or floating-point values. 4608@end deftypefn 4609 4610@deftypefn {Built-in Function} void __builtin_prefetch (const void *@var{addr}, ...) 4611This function is used to minimize cache-miss latency by moving data into 4612a cache before it is accessed. 4613You can insert calls to @code{__builtin_prefetch} into code for which 4614you know addresses of data in memory that is likely to be accessed soon. 4615If the target supports them, data prefetch instructions will be generated. 4616If the prefetch is done early enough before the access then the data will 4617be in the cache by the time it is accessed. 4618 4619The value of @var{addr} is the address of the memory to prefetch. 4620There are two optional arguments, @var{rw} and @var{locality}. 4621The value of @var{rw} is a compile-time constant one or zero; one 4622means that the prefetch is preparing for a write to the memory address 4623and zero, the default, means that the prefetch is preparing for a read. 4624The value @var{locality} must be a compile-time constant integer between 4625zero and three. A value of zero means that the data has no temporal 4626locality, so it need not be left in the cache after the access. A value 4627of three means that the data has a high degree of temporal locality and 4628should be left in all levels of cache possible. Values of one and two 4629mean, respectively, a low or moderate degree of temporal locality. The 4630default is three. 4631 4632@smallexample 4633for (i = 0; i < n; i++) 4634 @{ 4635 a[i] = a[i] + b[i]; 4636 __builtin_prefetch (&a[i+j], 1, 1); 4637 __builtin_prefetch (&b[i+j], 0, 1); 4638 /* ... */ 4639 @} 4640@end smallexample 4641 4642Data prefetch does not generate faults if @var{addr} is invalid, but 4643the address expression itself must be valid. For example, a prefetch 4644of @code{p->next} will not fault if @code{p->next} is not a valid 4645address, but evaluation will fault if @code{p} is not a valid address. 4646 4647If the target does not support data prefetch, the address expression 4648is evaluated if it includes side effects but no other code is generated 4649and GCC does not issue a warning. 4650@end deftypefn 4651 4652@node Target Builtins 4653@section Built-in Functions Specific to Particular Target Machines 4654 4655On some target machines, GCC supports many built-in functions specific 4656to those machines. Generally these generate calls to specific machine 4657instructions, but allow the compiler to schedule those calls. 4658 4659@menu 4660* X86 Built-in Functions:: 4661* PowerPC AltiVec Built-in Functions:: 4662@end menu 4663 4664@node X86 Built-in Functions 4665@subsection X86 Built-in Functions 4666 4667These built-in functions are available for the i386 and x86-64 family 4668of computers, depending on the command-line switches used. 4669 4670The following machine modes are available for use with MMX built-in functions 4671(@pxref{Vector Extensions}): @code{V2SI} for a vector of two 32-bit integers, 4672@code{V4HI} for a vector of four 16-bit integers, and @code{V8QI} for a 4673vector of eight 8-bit integers. Some of the built-in functions operate on 4674MMX registers as a whole 64-bit entity, these use @code{DI} as their mode. 4675 4676If 3Dnow extensions are enabled, @code{V2SF} is used as a mode for a vector 4677of two 32-bit floating point values. 4678 4679If SSE extensions are enabled, @code{V4SF} is used for a vector of four 32-bit 4680floating point values. Some instructions use a vector of four 32-bit 4681integers, these use @code{V4SI}. Finally, some instructions operate on an 4682entire vector register, interpreting it as a 128-bit integer, these use mode 4683@code{TI}. 4684 4685The following built-in functions are made available by @option{-mmmx}. 4686All of them generate the machine instruction that is part of the name. 4687 4688@example 4689v8qi __builtin_ia32_paddb (v8qi, v8qi) 4690v4hi __builtin_ia32_paddw (v4hi, v4hi) 4691v2si __builtin_ia32_paddd (v2si, v2si) 4692v8qi __builtin_ia32_psubb (v8qi, v8qi) 4693v4hi __builtin_ia32_psubw (v4hi, v4hi) 4694v2si __builtin_ia32_psubd (v2si, v2si) 4695v8qi __builtin_ia32_paddsb (v8qi, v8qi) 4696v4hi __builtin_ia32_paddsw (v4hi, v4hi) 4697v8qi __builtin_ia32_psubsb (v8qi, v8qi) 4698v4hi __builtin_ia32_psubsw (v4hi, v4hi) 4699v8qi __builtin_ia32_paddusb (v8qi, v8qi) 4700v4hi __builtin_ia32_paddusw (v4hi, v4hi) 4701v8qi __builtin_ia32_psubusb (v8qi, v8qi) 4702v4hi __builtin_ia32_psubusw (v4hi, v4hi) 4703v4hi __builtin_ia32_pmullw (v4hi, v4hi) 4704v4hi __builtin_ia32_pmulhw (v4hi, v4hi) 4705di __builtin_ia32_pand (di, di) 4706di __builtin_ia32_pandn (di,di) 4707di __builtin_ia32_por (di, di) 4708di __builtin_ia32_pxor (di, di) 4709v8qi __builtin_ia32_pcmpeqb (v8qi, v8qi) 4710v4hi __builtin_ia32_pcmpeqw (v4hi, v4hi) 4711v2si __builtin_ia32_pcmpeqd (v2si, v2si) 4712v8qi __builtin_ia32_pcmpgtb (v8qi, v8qi) 4713v4hi __builtin_ia32_pcmpgtw (v4hi, v4hi) 4714v2si __builtin_ia32_pcmpgtd (v2si, v2si) 4715v8qi __builtin_ia32_punpckhbw (v8qi, v8qi) 4716v4hi __builtin_ia32_punpckhwd (v4hi, v4hi) 4717v2si __builtin_ia32_punpckhdq (v2si, v2si) 4718v8qi __builtin_ia32_punpcklbw (v8qi, v8qi) 4719v4hi __builtin_ia32_punpcklwd (v4hi, v4hi) 4720v2si __builtin_ia32_punpckldq (v2si, v2si) 4721v8qi __builtin_ia32_packsswb (v4hi, v4hi) 4722v4hi __builtin_ia32_packssdw (v2si, v2si) 4723v8qi __builtin_ia32_packuswb (v4hi, v4hi) 4724@end example 4725 4726The following built-in functions are made available either with 4727@option{-msse}, or with a combination of @option{-m3dnow} and 4728@option{-march=athlon}. All of them generate the machine 4729instruction that is part of the name. 4730 4731@example 4732v4hi __builtin_ia32_pmulhuw (v4hi, v4hi) 4733v8qi __builtin_ia32_pavgb (v8qi, v8qi) 4734v4hi __builtin_ia32_pavgw (v4hi, v4hi) 4735v4hi __builtin_ia32_psadbw (v8qi, v8qi) 4736v8qi __builtin_ia32_pmaxub (v8qi, v8qi) 4737v4hi __builtin_ia32_pmaxsw (v4hi, v4hi) 4738v8qi __builtin_ia32_pminub (v8qi, v8qi) 4739v4hi __builtin_ia32_pminsw (v4hi, v4hi) 4740int __builtin_ia32_pextrw (v4hi, int) 4741v4hi __builtin_ia32_pinsrw (v4hi, int, int) 4742int __builtin_ia32_pmovmskb (v8qi) 4743void __builtin_ia32_maskmovq (v8qi, v8qi, char *) 4744void __builtin_ia32_movntq (di *, di) 4745void __builtin_ia32_sfence (void) 4746@end example 4747 4748The following built-in functions are available when @option{-msse} is used. 4749All of them generate the machine instruction that is part of the name. 4750 4751@example 4752int __builtin_ia32_comieq (v4sf, v4sf) 4753int __builtin_ia32_comineq (v4sf, v4sf) 4754int __builtin_ia32_comilt (v4sf, v4sf) 4755int __builtin_ia32_comile (v4sf, v4sf) 4756int __builtin_ia32_comigt (v4sf, v4sf) 4757int __builtin_ia32_comige (v4sf, v4sf) 4758int __builtin_ia32_ucomieq (v4sf, v4sf) 4759int __builtin_ia32_ucomineq (v4sf, v4sf) 4760int __builtin_ia32_ucomilt (v4sf, v4sf) 4761int __builtin_ia32_ucomile (v4sf, v4sf) 4762int __builtin_ia32_ucomigt (v4sf, v4sf) 4763int __builtin_ia32_ucomige (v4sf, v4sf) 4764v4sf __builtin_ia32_addps (v4sf, v4sf) 4765v4sf __builtin_ia32_subps (v4sf, v4sf) 4766v4sf __builtin_ia32_mulps (v4sf, v4sf) 4767v4sf __builtin_ia32_divps (v4sf, v4sf) 4768v4sf __builtin_ia32_addss (v4sf, v4sf) 4769v4sf __builtin_ia32_subss (v4sf, v4sf) 4770v4sf __builtin_ia32_mulss (v4sf, v4sf) 4771v4sf __builtin_ia32_divss (v4sf, v4sf) 4772v4si __builtin_ia32_cmpeqps (v4sf, v4sf) 4773v4si __builtin_ia32_cmpltps (v4sf, v4sf) 4774v4si __builtin_ia32_cmpleps (v4sf, v4sf) 4775v4si __builtin_ia32_cmpgtps (v4sf, v4sf) 4776v4si __builtin_ia32_cmpgeps (v4sf, v4sf) 4777v4si __builtin_ia32_cmpunordps (v4sf, v4sf) 4778v4si __builtin_ia32_cmpneqps (v4sf, v4sf) 4779v4si __builtin_ia32_cmpnltps (v4sf, v4sf) 4780v4si __builtin_ia32_cmpnleps (v4sf, v4sf) 4781v4si __builtin_ia32_cmpngtps (v4sf, v4sf) 4782v4si __builtin_ia32_cmpngeps (v4sf, v4sf) 4783v4si __builtin_ia32_cmpordps (v4sf, v4sf) 4784v4si __builtin_ia32_cmpeqss (v4sf, v4sf) 4785v4si __builtin_ia32_cmpltss (v4sf, v4sf) 4786v4si __builtin_ia32_cmpless (v4sf, v4sf) 4787v4si __builtin_ia32_cmpgtss (v4sf, v4sf) 4788v4si __builtin_ia32_cmpgess (v4sf, v4sf) 4789v4si __builtin_ia32_cmpunordss (v4sf, v4sf) 4790v4si __builtin_ia32_cmpneqss (v4sf, v4sf) 4791v4si __builtin_ia32_cmpnlts (v4sf, v4sf) 4792v4si __builtin_ia32_cmpnless (v4sf, v4sf) 4793v4si __builtin_ia32_cmpngtss (v4sf, v4sf) 4794v4si __builtin_ia32_cmpngess (v4sf, v4sf) 4795v4si __builtin_ia32_cmpordss (v4sf, v4sf) 4796v4sf __builtin_ia32_maxps (v4sf, v4sf) 4797v4sf __builtin_ia32_maxss (v4sf, v4sf) 4798v4sf __builtin_ia32_minps (v4sf, v4sf) 4799v4sf __builtin_ia32_minss (v4sf, v4sf) 4800v4sf __builtin_ia32_andps (v4sf, v4sf) 4801v4sf __builtin_ia32_andnps (v4sf, v4sf) 4802v4sf __builtin_ia32_orps (v4sf, v4sf) 4803v4sf __builtin_ia32_xorps (v4sf, v4sf) 4804v4sf __builtin_ia32_movss (v4sf, v4sf) 4805v4sf __builtin_ia32_movhlps (v4sf, v4sf) 4806v4sf __builtin_ia32_movlhps (v4sf, v4sf) 4807v4sf __builtin_ia32_unpckhps (v4sf, v4sf) 4808v4sf __builtin_ia32_unpcklps (v4sf, v4sf) 4809v4sf __builtin_ia32_cvtpi2ps (v4sf, v2si) 4810v4sf __builtin_ia32_cvtsi2ss (v4sf, int) 4811v2si __builtin_ia32_cvtps2pi (v4sf) 4812int __builtin_ia32_cvtss2si (v4sf) 4813v2si __builtin_ia32_cvttps2pi (v4sf) 4814int __builtin_ia32_cvttss2si (v4sf) 4815v4sf __builtin_ia32_rcpps (v4sf) 4816v4sf __builtin_ia32_rsqrtps (v4sf) 4817v4sf __builtin_ia32_sqrtps (v4sf) 4818v4sf __builtin_ia32_rcpss (v4sf) 4819v4sf __builtin_ia32_rsqrtss (v4sf) 4820v4sf __builtin_ia32_sqrtss (v4sf) 4821v4sf __builtin_ia32_shufps (v4sf, v4sf, int) 4822void __builtin_ia32_movntps (float *, v4sf) 4823int __builtin_ia32_movmskps (v4sf) 4824@end example 4825 4826The following built-in functions are available when @option{-msse} is used. 4827 4828@table @code 4829@item v4sf __builtin_ia32_loadaps (float *) 4830Generates the @code{movaps} machine instruction as a load from memory. 4831@item void __builtin_ia32_storeaps (float *, v4sf) 4832Generates the @code{movaps} machine instruction as a store to memory. 4833@item v4sf __builtin_ia32_loadups (float *) 4834Generates the @code{movups} machine instruction as a load from memory. 4835@item void __builtin_ia32_storeups (float *, v4sf) 4836Generates the @code{movups} machine instruction as a store to memory. 4837@item v4sf __builtin_ia32_loadsss (float *) 4838Generates the @code{movss} machine instruction as a load from memory. 4839@item void __builtin_ia32_storess (float *, v4sf) 4840Generates the @code{movss} machine instruction as a store to memory. 4841@item v4sf __builtin_ia32_loadhps (v4sf, v2si *) 4842Generates the @code{movhps} machine instruction as a load from memory. 4843@item v4sf __builtin_ia32_loadlps (v4sf, v2si *) 4844Generates the @code{movlps} machine instruction as a load from memory 4845@item void __builtin_ia32_storehps (v4sf, v2si *) 4846Generates the @code{movhps} machine instruction as a store to memory. 4847@item void __builtin_ia32_storelps (v4sf, v2si *) 4848Generates the @code{movlps} machine instruction as a store to memory. 4849@end table 4850 4851The following built-in functions are available when @option{-m3dnow} is used. 4852All of them generate the machine instruction that is part of the name. 4853 4854@example 4855void __builtin_ia32_femms (void) 4856v8qi __builtin_ia32_pavgusb (v8qi, v8qi) 4857v2si __builtin_ia32_pf2id (v2sf) 4858v2sf __builtin_ia32_pfacc (v2sf, v2sf) 4859v2sf __builtin_ia32_pfadd (v2sf, v2sf) 4860v2si __builtin_ia32_pfcmpeq (v2sf, v2sf) 4861v2si __builtin_ia32_pfcmpge (v2sf, v2sf) 4862v2si __builtin_ia32_pfcmpgt (v2sf, v2sf) 4863v2sf __builtin_ia32_pfmax (v2sf, v2sf) 4864v2sf __builtin_ia32_pfmin (v2sf, v2sf) 4865v2sf __builtin_ia32_pfmul (v2sf, v2sf) 4866v2sf __builtin_ia32_pfrcp (v2sf) 4867v2sf __builtin_ia32_pfrcpit1 (v2sf, v2sf) 4868v2sf __builtin_ia32_pfrcpit2 (v2sf, v2sf) 4869v2sf __builtin_ia32_pfrsqrt (v2sf) 4870v2sf __builtin_ia32_pfrsqrtit1 (v2sf, v2sf) 4871v2sf __builtin_ia32_pfsub (v2sf, v2sf) 4872v2sf __builtin_ia32_pfsubr (v2sf, v2sf) 4873v2sf __builtin_ia32_pi2fd (v2si) 4874v4hi __builtin_ia32_pmulhrw (v4hi, v4hi) 4875@end example 4876 4877The following built-in functions are available when both @option{-m3dnow} 4878and @option{-march=athlon} are used. All of them generate the machine 4879instruction that is part of the name. 4880 4881@example 4882v2si __builtin_ia32_pf2iw (v2sf) 4883v2sf __builtin_ia32_pfnacc (v2sf, v2sf) 4884v2sf __builtin_ia32_pfpnacc (v2sf, v2sf) 4885v2sf __builtin_ia32_pi2fw (v2si) 4886v2sf __builtin_ia32_pswapdsf (v2sf) 4887v2si __builtin_ia32_pswapdsi (v2si) 4888@end example 4889 4890@node PowerPC AltiVec Built-in Functions 4891@subsection PowerPC AltiVec Built-in Functions 4892 4893These built-in functions are available for the PowerPC family 4894of computers, depending on the command-line switches used. 4895 4896The following machine modes are available for use with AltiVec built-in 4897functions (@pxref{Vector Extensions}): @code{V4SI} for a vector of four 489832-bit integers, @code{V4SF} for a vector of four 32-bit floating point 4899numbers, @code{V8HI} for a vector of eight 16-bit integers, and 4900@code{V16QI} for a vector of sixteen 8-bit integers. 4901 4902The following functions are made available by including 4903@code{<altivec.h>} and using @option{-maltivec} and 4904@option{-mabi=altivec}. The functions implement the functionality 4905described in Motorola's AltiVec Programming Interface Manual. 4906 4907@emph{Note:} Only the @code{<altivec.h>} interface is supported. 4908Internally, GCC uses built-in functions to achieve the functionality in 4909the aforementioned header file, but they are not supported and are 4910subject to change without notice. 4911 4912@smallexample 4913vector signed char vec_abs (vector signed char, vector signed char); 4914vector signed short vec_abs (vector signed short, vector signed short); 4915vector signed int vec_abs (vector signed int, vector signed int); 4916vector signed float vec_abs (vector signed float, vector signed float); 4917 4918vector signed char vec_abss (vector signed char, vector signed char); 4919vector signed short vec_abss (vector signed short, vector signed short); 4920 4921vector signed char vec_add (vector signed char, vector signed char); 4922vector unsigned char vec_add (vector signed char, vector unsigned char); 4923 4924vector unsigned char vec_add (vector unsigned char, vector signed char); 4925 4926vector unsigned char vec_add (vector unsigned char, 4927 vector unsigned char); 4928vector signed short vec_add (vector signed short, vector signed short); 4929vector unsigned short vec_add (vector signed short, 4930 vector unsigned short); 4931vector unsigned short vec_add (vector unsigned short, 4932 vector signed short); 4933vector unsigned short vec_add (vector unsigned short, 4934 vector unsigned short); 4935vector signed int vec_add (vector signed int, vector signed int); 4936vector unsigned int vec_add (vector signed int, vector unsigned int); 4937vector unsigned int vec_add (vector unsigned int, vector signed int); 4938vector unsigned int vec_add (vector unsigned int, vector unsigned int); 4939vector float vec_add (vector float, vector float); 4940 4941vector unsigned int vec_addc (vector unsigned int, vector unsigned int); 4942 4943vector unsigned char vec_adds (vector signed char, 4944 vector unsigned char); 4945vector unsigned char vec_adds (vector unsigned char, 4946 vector signed char); 4947vector unsigned char vec_adds (vector unsigned char, 4948 vector unsigned char); 4949vector signed char vec_adds (vector signed char, vector signed char); 4950vector unsigned short vec_adds (vector signed short, 4951 vector unsigned short); 4952vector unsigned short vec_adds (vector unsigned short, 4953 vector signed short); 4954vector unsigned short vec_adds (vector unsigned short, 4955 vector unsigned short); 4956vector signed short vec_adds (vector signed short, vector signed short); 4957 4958vector unsigned int vec_adds (vector signed int, vector unsigned int); 4959vector unsigned int vec_adds (vector unsigned int, vector signed int); 4960vector unsigned int vec_adds (vector unsigned int, vector unsigned int); 4961 4962vector signed int vec_adds (vector signed int, vector signed int); 4963 4964vector float vec_and (vector float, vector float); 4965vector float vec_and (vector float, vector signed int); 4966vector float vec_and (vector signed int, vector float); 4967vector signed int vec_and (vector signed int, vector signed int); 4968vector unsigned int vec_and (vector signed int, vector unsigned int); 4969vector unsigned int vec_and (vector unsigned int, vector signed int); 4970vector unsigned int vec_and (vector unsigned int, vector unsigned int); 4971vector signed short vec_and (vector signed short, vector signed short); 4972vector unsigned short vec_and (vector signed short, 4973 vector unsigned short); 4974vector unsigned short vec_and (vector unsigned short, 4975 vector signed short); 4976vector unsigned short vec_and (vector unsigned short, 4977 vector unsigned short); 4978vector signed char vec_and (vector signed char, vector signed char); 4979vector unsigned char vec_and (vector signed char, vector unsigned char); 4980 4981vector unsigned char vec_and (vector unsigned char, vector signed char); 4982 4983vector unsigned char vec_and (vector unsigned char, 4984 vector unsigned char); 4985 4986vector float vec_andc (vector float, vector float); 4987vector float vec_andc (vector float, vector signed int); 4988vector float vec_andc (vector signed int, vector float); 4989vector signed int vec_andc (vector signed int, vector signed int); 4990vector unsigned int vec_andc (vector signed int, vector unsigned int); 4991vector unsigned int vec_andc (vector unsigned int, vector signed int); 4992vector unsigned int vec_andc (vector unsigned int, vector unsigned int); 4993 4994vector signed short vec_andc (vector signed short, vector signed short); 4995 4996vector unsigned short vec_andc (vector signed short, 4997 vector unsigned short); 4998vector unsigned short vec_andc (vector unsigned short, 4999 vector signed short); 5000vector unsigned short vec_andc (vector unsigned short, 5001 vector unsigned short); 5002vector signed char vec_andc (vector signed char, vector signed char); 5003vector unsigned char vec_andc (vector signed char, 5004 vector unsigned char); 5005vector unsigned char vec_andc (vector unsigned char, 5006 vector signed char); 5007vector unsigned char vec_andc (vector unsigned char, 5008 vector unsigned char); 5009 5010vector unsigned char vec_avg (vector unsigned char, 5011 vector unsigned char); 5012vector signed char vec_avg (vector signed char, vector signed char); 5013vector unsigned short vec_avg (vector unsigned short, 5014 vector unsigned short); 5015vector signed short vec_avg (vector signed short, vector signed short); 5016vector unsigned int vec_avg (vector unsigned int, vector unsigned int); 5017vector signed int vec_avg (vector signed int, vector signed int); 5018 5019vector float vec_ceil (vector float); 5020 5021vector signed int vec_cmpb (vector float, vector float); 5022 5023vector signed char vec_cmpeq (vector signed char, vector signed char); 5024vector signed char vec_cmpeq (vector unsigned char, 5025 vector unsigned char); 5026vector signed short vec_cmpeq (vector signed short, 5027 vector signed short); 5028vector signed short vec_cmpeq (vector unsigned short, 5029 vector unsigned short); 5030vector signed int vec_cmpeq (vector signed int, vector signed int); 5031vector signed int vec_cmpeq (vector unsigned int, vector unsigned int); 5032vector signed int vec_cmpeq (vector float, vector float); 5033 5034vector signed int vec_cmpge (vector float, vector float); 5035 5036vector signed char vec_cmpgt (vector unsigned char, 5037 vector unsigned char); 5038vector signed char vec_cmpgt (vector signed char, vector signed char); 5039vector signed short vec_cmpgt (vector unsigned short, 5040 vector unsigned short); 5041vector signed short vec_cmpgt (vector signed short, 5042 vector signed short); 5043vector signed int vec_cmpgt (vector unsigned int, vector unsigned int); 5044vector signed int vec_cmpgt (vector signed int, vector signed int); 5045vector signed int vec_cmpgt (vector float, vector float); 5046 5047vector signed int vec_cmple (vector float, vector float); 5048 5049vector signed char vec_cmplt (vector unsigned char, 5050 vector unsigned char); 5051vector signed char vec_cmplt (vector signed char, vector signed char); 5052vector signed short vec_cmplt (vector unsigned short, 5053 vector unsigned short); 5054vector signed short vec_cmplt (vector signed short, 5055 vector signed short); 5056vector signed int vec_cmplt (vector unsigned int, vector unsigned int); 5057vector signed int vec_cmplt (vector signed int, vector signed int); 5058vector signed int vec_cmplt (vector float, vector float); 5059 5060vector float vec_ctf (vector unsigned int, const char); 5061vector float vec_ctf (vector signed int, const char); 5062 5063vector signed int vec_cts (vector float, const char); 5064 5065vector unsigned int vec_ctu (vector float, const char); 5066 5067void vec_dss (const char); 5068 5069void vec_dssall (void); 5070 5071void vec_dst (void *, int, const char); 5072 5073void vec_dstst (void *, int, const char); 5074 5075void vec_dststt (void *, int, const char); 5076 5077void vec_dstt (void *, int, const char); 5078 5079vector float vec_expte (vector float, vector float); 5080 5081vector float vec_floor (vector float, vector float); 5082 5083vector float vec_ld (int, vector float *); 5084vector float vec_ld (int, float *): 5085vector signed int vec_ld (int, int *); 5086vector signed int vec_ld (int, vector signed int *); 5087vector unsigned int vec_ld (int, vector unsigned int *); 5088vector unsigned int vec_ld (int, unsigned int *); 5089vector signed short vec_ld (int, short *, vector signed short *); 5090vector unsigned short vec_ld (int, unsigned short *, 5091 vector unsigned short *); 5092vector signed char vec_ld (int, signed char *); 5093vector signed char vec_ld (int, vector signed char *); 5094vector unsigned char vec_ld (int, unsigned char *); 5095vector unsigned char vec_ld (int, vector unsigned char *); 5096 5097vector signed char vec_lde (int, signed char *); 5098vector unsigned char vec_lde (int, unsigned char *); 5099vector signed short vec_lde (int, short *); 5100vector unsigned short vec_lde (int, unsigned short *); 5101vector float vec_lde (int, float *); 5102vector signed int vec_lde (int, int *); 5103vector unsigned int vec_lde (int, unsigned int *); 5104 5105void float vec_ldl (int, float *); 5106void float vec_ldl (int, vector float *); 5107void signed int vec_ldl (int, vector signed int *); 5108void signed int vec_ldl (int, int *); 5109void unsigned int vec_ldl (int, unsigned int *); 5110void unsigned int vec_ldl (int, vector unsigned int *); 5111void signed short vec_ldl (int, vector signed short *); 5112void signed short vec_ldl (int, short *); 5113void unsigned short vec_ldl (int, vector unsigned short *); 5114void unsigned short vec_ldl (int, unsigned short *); 5115void signed char vec_ldl (int, vector signed char *); 5116void signed char vec_ldl (int, signed char *); 5117void unsigned char vec_ldl (int, vector unsigned char *); 5118void unsigned char vec_ldl (int, unsigned char *); 5119 5120vector float vec_loge (vector float); 5121 5122vector unsigned char vec_lvsl (int, void *, int *); 5123 5124vector unsigned char vec_lvsr (int, void *, int *); 5125 5126vector float vec_madd (vector float, vector float, vector float); 5127 5128vector signed short vec_madds (vector signed short, vector signed short, 5129 vector signed short); 5130 5131vector unsigned char vec_max (vector signed char, vector unsigned char); 5132 5133vector unsigned char vec_max (vector unsigned char, vector signed char); 5134 5135vector unsigned char vec_max (vector unsigned char, 5136 vector unsigned char); 5137vector signed char vec_max (vector signed char, vector signed char); 5138vector unsigned short vec_max (vector signed short, 5139 vector unsigned short); 5140vector unsigned short vec_max (vector unsigned short, 5141 vector signed short); 5142vector unsigned short vec_max (vector unsigned short, 5143 vector unsigned short); 5144vector signed short vec_max (vector signed short, vector signed short); 5145vector unsigned int vec_max (vector signed int, vector unsigned int); 5146vector unsigned int vec_max (vector unsigned int, vector signed int); 5147vector unsigned int vec_max (vector unsigned int, vector unsigned int); 5148vector signed int vec_max (vector signed int, vector signed int); 5149vector float vec_max (vector float, vector float); 5150 5151vector signed char vec_mergeh (vector signed char, vector signed char); 5152vector unsigned char vec_mergeh (vector unsigned char, 5153 vector unsigned char); 5154vector signed short vec_mergeh (vector signed short, 5155 vector signed short); 5156vector unsigned short vec_mergeh (vector unsigned short, 5157 vector unsigned short); 5158vector float vec_mergeh (vector float, vector float); 5159vector signed int vec_mergeh (vector signed int, vector signed int); 5160vector unsigned int vec_mergeh (vector unsigned int, 5161 vector unsigned int); 5162 5163vector signed char vec_mergel (vector signed char, vector signed char); 5164vector unsigned char vec_mergel (vector unsigned char, 5165 vector unsigned char); 5166vector signed short vec_mergel (vector signed short, 5167 vector signed short); 5168vector unsigned short vec_mergel (vector unsigned short, 5169 vector unsigned short); 5170vector float vec_mergel (vector float, vector float); 5171vector signed int vec_mergel (vector signed int, vector signed int); 5172vector unsigned int vec_mergel (vector unsigned int, 5173 vector unsigned int); 5174 5175vector unsigned short vec_mfvscr (void); 5176 5177vector unsigned char vec_min (vector signed char, vector unsigned char); 5178 5179vector unsigned char vec_min (vector unsigned char, vector signed char); 5180 5181vector unsigned char vec_min (vector unsigned char, 5182 vector unsigned char); 5183vector signed char vec_min (vector signed char, vector signed char); 5184vector unsigned short vec_min (vector signed short, 5185 vector unsigned short); 5186vector unsigned short vec_min (vector unsigned short, 5187 vector signed short); 5188vector unsigned short vec_min (vector unsigned short, 5189 vector unsigned short); 5190vector signed short vec_min (vector signed short, vector signed short); 5191vector unsigned int vec_min (vector signed int, vector unsigned int); 5192vector unsigned int vec_min (vector unsigned int, vector signed int); 5193vector unsigned int vec_min (vector unsigned int, vector unsigned int); 5194vector signed int vec_min (vector signed int, vector signed int); 5195vector float vec_min (vector float, vector float); 5196 5197vector signed short vec_mladd (vector signed short, vector signed short, 5198 vector signed short); 5199vector signed short vec_mladd (vector signed short, 5200 vector unsigned short, 5201 vector unsigned short); 5202vector signed short vec_mladd (vector unsigned short, 5203 vector signed short, 5204 vector signed short); 5205vector unsigned short vec_mladd (vector unsigned short, 5206 vector unsigned short, 5207 vector unsigned short); 5208 5209vector signed short vec_mradds (vector signed short, 5210 vector signed short, 5211 vector signed short); 5212 5213vector unsigned int vec_msum (vector unsigned char, 5214 vector unsigned char, 5215 vector unsigned int); 5216vector signed int vec_msum (vector signed char, vector unsigned char, 5217 vector signed int); 5218vector unsigned int vec_msum (vector unsigned short, 5219 vector unsigned short, 5220 vector unsigned int); 5221vector signed int vec_msum (vector signed short, vector signed short, 5222 vector signed int); 5223 5224vector unsigned int vec_msums (vector unsigned short, 5225 vector unsigned short, 5226 vector unsigned int); 5227vector signed int vec_msums (vector signed short, vector signed short, 5228 vector signed int); 5229 5230void vec_mtvscr (vector signed int); 5231void vec_mtvscr (vector unsigned int); 5232void vec_mtvscr (vector signed short); 5233void vec_mtvscr (vector unsigned short); 5234void vec_mtvscr (vector signed char); 5235void vec_mtvscr (vector unsigned char); 5236 5237vector unsigned short vec_mule (vector unsigned char, 5238 vector unsigned char); 5239vector signed short vec_mule (vector signed char, vector signed char); 5240vector unsigned int vec_mule (vector unsigned short, 5241 vector unsigned short); 5242vector signed int vec_mule (vector signed short, vector signed short); 5243 5244vector unsigned short vec_mulo (vector unsigned char, 5245 vector unsigned char); 5246vector signed short vec_mulo (vector signed char, vector signed char); 5247vector unsigned int vec_mulo (vector unsigned short, 5248 vector unsigned short); 5249vector signed int vec_mulo (vector signed short, vector signed short); 5250 5251vector float vec_nmsub (vector float, vector float, vector float); 5252 5253vector float vec_nor (vector float, vector float); 5254vector signed int vec_nor (vector signed int, vector signed int); 5255vector unsigned int vec_nor (vector unsigned int, vector unsigned int); 5256vector signed short vec_nor (vector signed short, vector signed short); 5257vector unsigned short vec_nor (vector unsigned short, 5258 vector unsigned short); 5259vector signed char vec_nor (vector signed char, vector signed char); 5260vector unsigned char vec_nor (vector unsigned char, 5261 vector unsigned char); 5262 5263vector float vec_or (vector float, vector float); 5264vector float vec_or (vector float, vector signed int); 5265vector float vec_or (vector signed int, vector float); 5266vector signed int vec_or (vector signed int, vector signed int); 5267vector unsigned int vec_or (vector signed int, vector unsigned int); 5268vector unsigned int vec_or (vector unsigned int, vector signed int); 5269vector unsigned int vec_or (vector unsigned int, vector unsigned int); 5270vector signed short vec_or (vector signed short, vector signed short); 5271vector unsigned short vec_or (vector signed short, 5272 vector unsigned short); 5273vector unsigned short vec_or (vector unsigned short, 5274 vector signed short); 5275vector unsigned short vec_or (vector unsigned short, 5276 vector unsigned short); 5277vector signed char vec_or (vector signed char, vector signed char); 5278vector unsigned char vec_or (vector signed char, vector unsigned char); 5279vector unsigned char vec_or (vector unsigned char, vector signed char); 5280vector unsigned char vec_or (vector unsigned char, 5281 vector unsigned char); 5282 5283vector signed char vec_pack (vector signed short, vector signed short); 5284vector unsigned char vec_pack (vector unsigned short, 5285 vector unsigned short); 5286vector signed short vec_pack (vector signed int, vector signed int); 5287vector unsigned short vec_pack (vector unsigned int, 5288 vector unsigned int); 5289 5290vector signed short vec_packpx (vector unsigned int, 5291 vector unsigned int); 5292 5293vector unsigned char vec_packs (vector unsigned short, 5294 vector unsigned short); 5295vector signed char vec_packs (vector signed short, vector signed short); 5296 5297vector unsigned short vec_packs (vector unsigned int, 5298 vector unsigned int); 5299vector signed short vec_packs (vector signed int, vector signed int); 5300 5301vector unsigned char vec_packsu (vector unsigned short, 5302 vector unsigned short); 5303vector unsigned char vec_packsu (vector signed short, 5304 vector signed short); 5305vector unsigned short vec_packsu (vector unsigned int, 5306 vector unsigned int); 5307vector unsigned short vec_packsu (vector signed int, vector signed int); 5308 5309vector float vec_perm (vector float, vector float, 5310 vector unsigned char); 5311vector signed int vec_perm (vector signed int, vector signed int, 5312 vector unsigned char); 5313vector unsigned int vec_perm (vector unsigned int, vector unsigned int, 5314 vector unsigned char); 5315vector signed short vec_perm (vector signed short, vector signed short, 5316 vector unsigned char); 5317vector unsigned short vec_perm (vector unsigned short, 5318 vector unsigned short, 5319 vector unsigned char); 5320vector signed char vec_perm (vector signed char, vector signed char, 5321 vector unsigned char); 5322vector unsigned char vec_perm (vector unsigned char, 5323 vector unsigned char, 5324 vector unsigned char); 5325 5326vector float vec_re (vector float); 5327 5328vector signed char vec_rl (vector signed char, vector unsigned char); 5329vector unsigned char vec_rl (vector unsigned char, 5330 vector unsigned char); 5331vector signed short vec_rl (vector signed short, vector unsigned short); 5332 5333vector unsigned short vec_rl (vector unsigned short, 5334 vector unsigned short); 5335vector signed int vec_rl (vector signed int, vector unsigned int); 5336vector unsigned int vec_rl (vector unsigned int, vector unsigned int); 5337 5338vector float vec_round (vector float); 5339 5340vector float vec_rsqrte (vector float); 5341 5342vector float vec_sel (vector float, vector float, vector signed int); 5343vector float vec_sel (vector float, vector float, vector unsigned int); 5344vector signed int vec_sel (vector signed int, vector signed int, 5345 vector signed int); 5346vector signed int vec_sel (vector signed int, vector signed int, 5347 vector unsigned int); 5348vector unsigned int vec_sel (vector unsigned int, vector unsigned int, 5349 vector signed int); 5350vector unsigned int vec_sel (vector unsigned int, vector unsigned int, 5351 vector unsigned int); 5352vector signed short vec_sel (vector signed short, vector signed short, 5353 vector signed short); 5354vector signed short vec_sel (vector signed short, vector signed short, 5355 vector unsigned short); 5356vector unsigned short vec_sel (vector unsigned short, 5357 vector unsigned short, 5358 vector signed short); 5359vector unsigned short vec_sel (vector unsigned short, 5360 vector unsigned short, 5361 vector unsigned short); 5362vector signed char vec_sel (vector signed char, vector signed char, 5363 vector signed char); 5364vector signed char vec_sel (vector signed char, vector signed char, 5365 vector unsigned char); 5366vector unsigned char vec_sel (vector unsigned char, 5367 vector unsigned char, 5368 vector signed char); 5369vector unsigned char vec_sel (vector unsigned char, 5370 vector unsigned char, 5371 vector unsigned char); 5372 5373vector signed char vec_sl (vector signed char, vector unsigned char); 5374vector unsigned char vec_sl (vector unsigned char, 5375 vector unsigned char); 5376vector signed short vec_sl (vector signed short, vector unsigned short); 5377 5378vector unsigned short vec_sl (vector unsigned short, 5379 vector unsigned short); 5380vector signed int vec_sl (vector signed int, vector unsigned int); 5381vector unsigned int vec_sl (vector unsigned int, vector unsigned int); 5382 5383vector float vec_sld (vector float, vector float, const char); 5384vector signed int vec_sld (vector signed int, vector signed int, 5385 const char); 5386vector unsigned int vec_sld (vector unsigned int, vector unsigned int, 5387 const char); 5388vector signed short vec_sld (vector signed short, vector signed short, 5389 const char); 5390vector unsigned short vec_sld (vector unsigned short, 5391 vector unsigned short, const char); 5392vector signed char vec_sld (vector signed char, vector signed char, 5393 const char); 5394vector unsigned char vec_sld (vector unsigned char, 5395 vector unsigned char, 5396 const char); 5397 5398vector signed int vec_sll (vector signed int, vector unsigned int); 5399vector signed int vec_sll (vector signed int, vector unsigned short); 5400vector signed int vec_sll (vector signed int, vector unsigned char); 5401vector unsigned int vec_sll (vector unsigned int, vector unsigned int); 5402vector unsigned int vec_sll (vector unsigned int, 5403 vector unsigned short); 5404vector unsigned int vec_sll (vector unsigned int, vector unsigned char); 5405 5406vector signed short vec_sll (vector signed short, vector unsigned int); 5407vector signed short vec_sll (vector signed short, 5408 vector unsigned short); 5409vector signed short vec_sll (vector signed short, vector unsigned char); 5410 5411vector unsigned short vec_sll (vector unsigned short, 5412 vector unsigned int); 5413vector unsigned short vec_sll (vector unsigned short, 5414 vector unsigned short); 5415vector unsigned short vec_sll (vector unsigned short, 5416 vector unsigned char); 5417vector signed char vec_sll (vector signed char, vector unsigned int); 5418vector signed char vec_sll (vector signed char, vector unsigned short); 5419vector signed char vec_sll (vector signed char, vector unsigned char); 5420vector unsigned char vec_sll (vector unsigned char, 5421 vector unsigned int); 5422vector unsigned char vec_sll (vector unsigned char, 5423 vector unsigned short); 5424vector unsigned char vec_sll (vector unsigned char, 5425 vector unsigned char); 5426 5427vector float vec_slo (vector float, vector signed char); 5428vector float vec_slo (vector float, vector unsigned char); 5429vector signed int vec_slo (vector signed int, vector signed char); 5430vector signed int vec_slo (vector signed int, vector unsigned char); 5431vector unsigned int vec_slo (vector unsigned int, vector signed char); 5432vector unsigned int vec_slo (vector unsigned int, vector unsigned char); 5433 5434vector signed short vec_slo (vector signed short, vector signed char); 5435vector signed short vec_slo (vector signed short, vector unsigned char); 5436 5437vector unsigned short vec_slo (vector unsigned short, 5438 vector signed char); 5439vector unsigned short vec_slo (vector unsigned short, 5440 vector unsigned char); 5441vector signed char vec_slo (vector signed char, vector signed char); 5442vector signed char vec_slo (vector signed char, vector unsigned char); 5443vector unsigned char vec_slo (vector unsigned char, vector signed char); 5444 5445vector unsigned char vec_slo (vector unsigned char, 5446 vector unsigned char); 5447 5448vector signed char vec_splat (vector signed char, const char); 5449vector unsigned char vec_splat (vector unsigned char, const char); 5450vector signed short vec_splat (vector signed short, const char); 5451vector unsigned short vec_splat (vector unsigned short, const char); 5452vector float vec_splat (vector float, const char); 5453vector signed int vec_splat (vector signed int, const char); 5454vector unsigned int vec_splat (vector unsigned int, const char); 5455 5456vector signed char vec_splat_s8 (const char); 5457 5458vector signed short vec_splat_s16 (const char); 5459 5460vector signed int vec_splat_s32 (const char); 5461 5462vector unsigned char vec_splat_u8 (const char); 5463 5464vector unsigned short vec_splat_u16 (const char); 5465 5466vector unsigned int vec_splat_u32 (const char); 5467 5468vector signed char vec_sr (vector signed char, vector unsigned char); 5469vector unsigned char vec_sr (vector unsigned char, 5470 vector unsigned char); 5471vector signed short vec_sr (vector signed short, vector unsigned short); 5472 5473vector unsigned short vec_sr (vector unsigned short, 5474 vector unsigned short); 5475vector signed int vec_sr (vector signed int, vector unsigned int); 5476vector unsigned int vec_sr (vector unsigned int, vector unsigned int); 5477 5478vector signed char vec_sra (vector signed char, vector unsigned char); 5479vector unsigned char vec_sra (vector unsigned char, 5480 vector unsigned char); 5481vector signed short vec_sra (vector signed short, 5482 vector unsigned short); 5483vector unsigned short vec_sra (vector unsigned short, 5484 vector unsigned short); 5485vector signed int vec_sra (vector signed int, vector unsigned int); 5486vector unsigned int vec_sra (vector unsigned int, vector unsigned int); 5487 5488vector signed int vec_srl (vector signed int, vector unsigned int); 5489vector signed int vec_srl (vector signed int, vector unsigned short); 5490vector signed int vec_srl (vector signed int, vector unsigned char); 5491vector unsigned int vec_srl (vector unsigned int, vector unsigned int); 5492vector unsigned int vec_srl (vector unsigned int, 5493 vector unsigned short); 5494vector unsigned int vec_srl (vector unsigned int, vector unsigned char); 5495 5496vector signed short vec_srl (vector signed short, vector unsigned int); 5497vector signed short vec_srl (vector signed short, 5498 vector unsigned short); 5499vector signed short vec_srl (vector signed short, vector unsigned char); 5500 5501vector unsigned short vec_srl (vector unsigned short, 5502 vector unsigned int); 5503vector unsigned short vec_srl (vector unsigned short, 5504 vector unsigned short); 5505vector unsigned short vec_srl (vector unsigned short, 5506 vector unsigned char); 5507vector signed char vec_srl (vector signed char, vector unsigned int); 5508vector signed char vec_srl (vector signed char, vector unsigned short); 5509vector signed char vec_srl (vector signed char, vector unsigned char); 5510vector unsigned char vec_srl (vector unsigned char, 5511 vector unsigned int); 5512vector unsigned char vec_srl (vector unsigned char, 5513 vector unsigned short); 5514vector unsigned char vec_srl (vector unsigned char, 5515 vector unsigned char); 5516 5517vector float vec_sro (vector float, vector signed char); 5518vector float vec_sro (vector float, vector unsigned char); 5519vector signed int vec_sro (vector signed int, vector signed char); 5520vector signed int vec_sro (vector signed int, vector unsigned char); 5521vector unsigned int vec_sro (vector unsigned int, vector signed char); 5522vector unsigned int vec_sro (vector unsigned int, vector unsigned char); 5523 5524vector signed short vec_sro (vector signed short, vector signed char); 5525vector signed short vec_sro (vector signed short, vector unsigned char); 5526 5527vector unsigned short vec_sro (vector unsigned short, 5528 vector signed char); 5529vector unsigned short vec_sro (vector unsigned short, 5530 vector unsigned char); 5531vector signed char vec_sro (vector signed char, vector signed char); 5532vector signed char vec_sro (vector signed char, vector unsigned char); 5533vector unsigned char vec_sro (vector unsigned char, vector signed char); 5534 5535vector unsigned char vec_sro (vector unsigned char, 5536 vector unsigned char); 5537 5538void vec_st (vector float, int, float *); 5539void vec_st (vector float, int, vector float *); 5540void vec_st (vector signed int, int, int *); 5541void vec_st (vector signed int, int, unsigned int *); 5542void vec_st (vector unsigned int, int, unsigned int *); 5543void vec_st (vector unsigned int, int, vector unsigned int *); 5544void vec_st (vector signed short, int, short *); 5545void vec_st (vector signed short, int, vector unsigned short *); 5546void vec_st (vector signed short, int, vector signed short *); 5547void vec_st (vector unsigned short, int, unsigned short *); 5548void vec_st (vector unsigned short, int, vector unsigned short *); 5549void vec_st (vector signed char, int, signed char *); 5550void vec_st (vector signed char, int, unsigned char *); 5551void vec_st (vector signed char, int, vector signed char *); 5552void vec_st (vector unsigned char, int, unsigned char *); 5553void vec_st (vector unsigned char, int, vector unsigned char *); 5554 5555void vec_ste (vector signed char, int, unsigned char *); 5556void vec_ste (vector signed char, int, signed char *); 5557void vec_ste (vector unsigned char, int, unsigned char *); 5558void vec_ste (vector signed short, int, short *); 5559void vec_ste (vector signed short, int, unsigned short *); 5560void vec_ste (vector unsigned short, int, void *); 5561void vec_ste (vector signed int, int, unsigned int *); 5562void vec_ste (vector signed int, int, int *); 5563void vec_ste (vector unsigned int, int, unsigned int *); 5564void vec_ste (vector float, int, float *); 5565 5566void vec_stl (vector float, int, vector float *); 5567void vec_stl (vector float, int, float *); 5568void vec_stl (vector signed int, int, vector signed int *); 5569void vec_stl (vector signed int, int, int *); 5570void vec_stl (vector signed int, int, unsigned int *); 5571void vec_stl (vector unsigned int, int, vector unsigned int *); 5572void vec_stl (vector unsigned int, int, unsigned int *); 5573void vec_stl (vector signed short, int, short *); 5574void vec_stl (vector signed short, int, unsigned short *); 5575void vec_stl (vector signed short, int, vector signed short *); 5576void vec_stl (vector unsigned short, int, unsigned short *); 5577void vec_stl (vector unsigned short, int, vector signed short *); 5578void vec_stl (vector signed char, int, signed char *); 5579void vec_stl (vector signed char, int, unsigned char *); 5580void vec_stl (vector signed char, int, vector signed char *); 5581void vec_stl (vector unsigned char, int, unsigned char *); 5582void vec_stl (vector unsigned char, int, vector unsigned char *); 5583 5584vector signed char vec_sub (vector signed char, vector signed char); 5585vector unsigned char vec_sub (vector signed char, vector unsigned char); 5586 5587vector unsigned char vec_sub (vector unsigned char, vector signed char); 5588 5589vector unsigned char vec_sub (vector unsigned char, 5590 vector unsigned char); 5591vector signed short vec_sub (vector signed short, vector signed short); 5592vector unsigned short vec_sub (vector signed short, 5593 vector unsigned short); 5594vector unsigned short vec_sub (vector unsigned short, 5595 vector signed short); 5596vector unsigned short vec_sub (vector unsigned short, 5597 vector unsigned short); 5598vector signed int vec_sub (vector signed int, vector signed int); 5599vector unsigned int vec_sub (vector signed int, vector unsigned int); 5600vector unsigned int vec_sub (vector unsigned int, vector signed int); 5601vector unsigned int vec_sub (vector unsigned int, vector unsigned int); 5602vector float vec_sub (vector float, vector float); 5603 5604vector unsigned int vec_subc (vector unsigned int, vector unsigned int); 5605 5606vector unsigned char vec_subs (vector signed char, 5607 vector unsigned char); 5608vector unsigned char vec_subs (vector unsigned char, 5609 vector signed char); 5610vector unsigned char vec_subs (vector unsigned char, 5611 vector unsigned char); 5612vector signed char vec_subs (vector signed char, vector signed char); 5613vector unsigned short vec_subs (vector signed short, 5614 vector unsigned short); 5615vector unsigned short vec_subs (vector unsigned short, 5616 vector signed short); 5617vector unsigned short vec_subs (vector unsigned short, 5618 vector unsigned short); 5619vector signed short vec_subs (vector signed short, vector signed short); 5620 5621vector unsigned int vec_subs (vector signed int, vector unsigned int); 5622vector unsigned int vec_subs (vector unsigned int, vector signed int); 5623vector unsigned int vec_subs (vector unsigned int, vector unsigned int); 5624 5625vector signed int vec_subs (vector signed int, vector signed int); 5626 5627vector unsigned int vec_sum4s (vector unsigned char, 5628 vector unsigned int); 5629vector signed int vec_sum4s (vector signed char, vector signed int); 5630vector signed int vec_sum4s (vector signed short, vector signed int); 5631 5632vector signed int vec_sum2s (vector signed int, vector signed int); 5633 5634vector signed int vec_sums (vector signed int, vector signed int); 5635 5636vector float vec_trunc (vector float); 5637 5638vector signed short vec_unpackh (vector signed char); 5639vector unsigned int vec_unpackh (vector signed short); 5640vector signed int vec_unpackh (vector signed short); 5641 5642vector signed short vec_unpackl (vector signed char); 5643vector unsigned int vec_unpackl (vector signed short); 5644vector signed int vec_unpackl (vector signed short); 5645 5646vector float vec_xor (vector float, vector float); 5647vector float vec_xor (vector float, vector signed int); 5648vector float vec_xor (vector signed int, vector float); 5649vector signed int vec_xor (vector signed int, vector signed int); 5650vector unsigned int vec_xor (vector signed int, vector unsigned int); 5651vector unsigned int vec_xor (vector unsigned int, vector signed int); 5652vector unsigned int vec_xor (vector unsigned int, vector unsigned int); 5653vector signed short vec_xor (vector signed short, vector signed short); 5654vector unsigned short vec_xor (vector signed short, 5655 vector unsigned short); 5656vector unsigned short vec_xor (vector unsigned short, 5657 vector signed short); 5658vector unsigned short vec_xor (vector unsigned short, 5659 vector unsigned short); 5660vector signed char vec_xor (vector signed char, vector signed char); 5661vector unsigned char vec_xor (vector signed char, vector unsigned char); 5662 5663vector unsigned char vec_xor (vector unsigned char, vector signed char); 5664 5665vector unsigned char vec_xor (vector unsigned char, 5666 vector unsigned char); 5667 5668vector signed int vec_all_eq (vector signed char, vector unsigned char); 5669 5670vector signed int vec_all_eq (vector signed char, vector signed char); 5671vector signed int vec_all_eq (vector unsigned char, vector signed char); 5672 5673vector signed int vec_all_eq (vector unsigned char, 5674 vector unsigned char); 5675vector signed int vec_all_eq (vector signed short, 5676 vector unsigned short); 5677vector signed int vec_all_eq (vector signed short, vector signed short); 5678 5679vector signed int vec_all_eq (vector unsigned short, 5680 vector signed short); 5681vector signed int vec_all_eq (vector unsigned short, 5682 vector unsigned short); 5683vector signed int vec_all_eq (vector signed int, vector unsigned int); 5684vector signed int vec_all_eq (vector signed int, vector signed int); 5685vector signed int vec_all_eq (vector unsigned int, vector signed int); 5686vector signed int vec_all_eq (vector unsigned int, vector unsigned int); 5687 5688vector signed int vec_all_eq (vector float, vector float); 5689 5690vector signed int vec_all_ge (vector signed char, vector unsigned char); 5691 5692vector signed int vec_all_ge (vector unsigned char, vector signed char); 5693 5694vector signed int vec_all_ge (vector unsigned char, 5695 vector unsigned char); 5696vector signed int vec_all_ge (vector signed char, vector signed char); 5697vector signed int vec_all_ge (vector signed short, 5698 vector unsigned short); 5699vector signed int vec_all_ge (vector unsigned short, 5700 vector signed short); 5701vector signed int vec_all_ge (vector unsigned short, 5702 vector unsigned short); 5703vector signed int vec_all_ge (vector signed short, vector signed short); 5704 5705vector signed int vec_all_ge (vector signed int, vector unsigned int); 5706vector signed int vec_all_ge (vector unsigned int, vector signed int); 5707vector signed int vec_all_ge (vector unsigned int, vector unsigned int); 5708 5709vector signed int vec_all_ge (vector signed int, vector signed int); 5710vector signed int vec_all_ge (vector float, vector float); 5711 5712vector signed int vec_all_gt (vector signed char, vector unsigned char); 5713 5714vector signed int vec_all_gt (vector unsigned char, vector signed char); 5715 5716vector signed int vec_all_gt (vector unsigned char, 5717 vector unsigned char); 5718vector signed int vec_all_gt (vector signed char, vector signed char); 5719vector signed int vec_all_gt (vector signed short, 5720 vector unsigned short); 5721vector signed int vec_all_gt (vector unsigned short, 5722 vector signed short); 5723vector signed int vec_all_gt (vector unsigned short, 5724 vector unsigned short); 5725vector signed int vec_all_gt (vector signed short, vector signed short); 5726 5727vector signed int vec_all_gt (vector signed int, vector unsigned int); 5728vector signed int vec_all_gt (vector unsigned int, vector signed int); 5729vector signed int vec_all_gt (vector unsigned int, vector unsigned int); 5730 5731vector signed int vec_all_gt (vector signed int, vector signed int); 5732vector signed int vec_all_gt (vector float, vector float); 5733 5734vector signed int vec_all_in (vector float, vector float); 5735 5736vector signed int vec_all_le (vector signed char, vector unsigned char); 5737 5738vector signed int vec_all_le (vector unsigned char, vector signed char); 5739 5740vector signed int vec_all_le (vector unsigned char, 5741 vector unsigned char); 5742vector signed int vec_all_le (vector signed char, vector signed char); 5743vector signed int vec_all_le (vector signed short, 5744 vector unsigned short); 5745vector signed int vec_all_le (vector unsigned short, 5746 vector signed short); 5747vector signed int vec_all_le (vector unsigned short, 5748 vector unsigned short); 5749vector signed int vec_all_le (vector signed short, vector signed short); 5750 5751vector signed int vec_all_le (vector signed int, vector unsigned int); 5752vector signed int vec_all_le (vector unsigned int, vector signed int); 5753vector signed int vec_all_le (vector unsigned int, vector unsigned int); 5754 5755vector signed int vec_all_le (vector signed int, vector signed int); 5756vector signed int vec_all_le (vector float, vector float); 5757 5758vector signed int vec_all_lt (vector signed char, vector unsigned char); 5759 5760vector signed int vec_all_lt (vector unsigned char, vector signed char); 5761 5762vector signed int vec_all_lt (vector unsigned char, 5763 vector unsigned char); 5764vector signed int vec_all_lt (vector signed char, vector signed char); 5765vector signed int vec_all_lt (vector signed short, 5766 vector unsigned short); 5767vector signed int vec_all_lt (vector unsigned short, 5768 vector signed short); 5769vector signed int vec_all_lt (vector unsigned short, 5770 vector unsigned short); 5771vector signed int vec_all_lt (vector signed short, vector signed short); 5772 5773vector signed int vec_all_lt (vector signed int, vector unsigned int); 5774vector signed int vec_all_lt (vector unsigned int, vector signed int); 5775vector signed int vec_all_lt (vector unsigned int, vector unsigned int); 5776 5777vector signed int vec_all_lt (vector signed int, vector signed int); 5778vector signed int vec_all_lt (vector float, vector float); 5779 5780vector signed int vec_all_nan (vector float); 5781 5782vector signed int vec_all_ne (vector signed char, vector unsigned char); 5783 5784vector signed int vec_all_ne (vector signed char, vector signed char); 5785vector signed int vec_all_ne (vector unsigned char, vector signed char); 5786 5787vector signed int vec_all_ne (vector unsigned char, 5788 vector unsigned char); 5789vector signed int vec_all_ne (vector signed short, 5790 vector unsigned short); 5791vector signed int vec_all_ne (vector signed short, vector signed short); 5792 5793vector signed int vec_all_ne (vector unsigned short, 5794 vector signed short); 5795vector signed int vec_all_ne (vector unsigned short, 5796 vector unsigned short); 5797vector signed int vec_all_ne (vector signed int, vector unsigned int); 5798vector signed int vec_all_ne (vector signed int, vector signed int); 5799vector signed int vec_all_ne (vector unsigned int, vector signed int); 5800vector signed int vec_all_ne (vector unsigned int, vector unsigned int); 5801 5802vector signed int vec_all_ne (vector float, vector float); 5803 5804vector signed int vec_all_nge (vector float, vector float); 5805 5806vector signed int vec_all_ngt (vector float, vector float); 5807 5808vector signed int vec_all_nle (vector float, vector float); 5809 5810vector signed int vec_all_nlt (vector float, vector float); 5811 5812vector signed int vec_all_numeric (vector float); 5813 5814vector signed int vec_any_eq (vector signed char, vector unsigned char); 5815 5816vector signed int vec_any_eq (vector signed char, vector signed char); 5817vector signed int vec_any_eq (vector unsigned char, vector signed char); 5818 5819vector signed int vec_any_eq (vector unsigned char, 5820 vector unsigned char); 5821vector signed int vec_any_eq (vector signed short, 5822 vector unsigned short); 5823vector signed int vec_any_eq (vector signed short, vector signed short); 5824 5825vector signed int vec_any_eq (vector unsigned short, 5826 vector signed short); 5827vector signed int vec_any_eq (vector unsigned short, 5828 vector unsigned short); 5829vector signed int vec_any_eq (vector signed int, vector unsigned int); 5830vector signed int vec_any_eq (vector signed int, vector signed int); 5831vector signed int vec_any_eq (vector unsigned int, vector signed int); 5832vector signed int vec_any_eq (vector unsigned int, vector unsigned int); 5833 5834vector signed int vec_any_eq (vector float, vector float); 5835 5836vector signed int vec_any_ge (vector signed char, vector unsigned char); 5837 5838vector signed int vec_any_ge (vector unsigned char, vector signed char); 5839 5840vector signed int vec_any_ge (vector unsigned char, 5841 vector unsigned char); 5842vector signed int vec_any_ge (vector signed char, vector signed char); 5843vector signed int vec_any_ge (vector signed short, 5844 vector unsigned short); 5845vector signed int vec_any_ge (vector unsigned short, 5846 vector signed short); 5847vector signed int vec_any_ge (vector unsigned short, 5848 vector unsigned short); 5849vector signed int vec_any_ge (vector signed short, vector signed short); 5850 5851vector signed int vec_any_ge (vector signed int, vector unsigned int); 5852vector signed int vec_any_ge (vector unsigned int, vector signed int); 5853vector signed int vec_any_ge (vector unsigned int, vector unsigned int); 5854 5855vector signed int vec_any_ge (vector signed int, vector signed int); 5856vector signed int vec_any_ge (vector float, vector float); 5857 5858vector signed int vec_any_gt (vector signed char, vector unsigned char); 5859 5860vector signed int vec_any_gt (vector unsigned char, vector signed char); 5861 5862vector signed int vec_any_gt (vector unsigned char, 5863 vector unsigned char); 5864vector signed int vec_any_gt (vector signed char, vector signed char); 5865vector signed int vec_any_gt (vector signed short, 5866 vector unsigned short); 5867vector signed int vec_any_gt (vector unsigned short, 5868 vector signed short); 5869vector signed int vec_any_gt (vector unsigned short, 5870 vector unsigned short); 5871vector signed int vec_any_gt (vector signed short, vector signed short); 5872 5873vector signed int vec_any_gt (vector signed int, vector unsigned int); 5874vector signed int vec_any_gt (vector unsigned int, vector signed int); 5875vector signed int vec_any_gt (vector unsigned int, vector unsigned int); 5876 5877vector signed int vec_any_gt (vector signed int, vector signed int); 5878vector signed int vec_any_gt (vector float, vector float); 5879 5880vector signed int vec_any_le (vector signed char, vector unsigned char); 5881 5882vector signed int vec_any_le (vector unsigned char, vector signed char); 5883 5884vector signed int vec_any_le (vector unsigned char, 5885 vector unsigned char); 5886vector signed int vec_any_le (vector signed char, vector signed char); 5887vector signed int vec_any_le (vector signed short, 5888 vector unsigned short); 5889vector signed int vec_any_le (vector unsigned short, 5890 vector signed short); 5891vector signed int vec_any_le (vector unsigned short, 5892 vector unsigned short); 5893vector signed int vec_any_le (vector signed short, vector signed short); 5894 5895vector signed int vec_any_le (vector signed int, vector unsigned int); 5896vector signed int vec_any_le (vector unsigned int, vector signed int); 5897vector signed int vec_any_le (vector unsigned int, vector unsigned int); 5898 5899vector signed int vec_any_le (vector signed int, vector signed int); 5900vector signed int vec_any_le (vector float, vector float); 5901 5902vector signed int vec_any_lt (vector signed char, vector unsigned char); 5903 5904vector signed int vec_any_lt (vector unsigned char, vector signed char); 5905 5906vector signed int vec_any_lt (vector unsigned char, 5907 vector unsigned char); 5908vector signed int vec_any_lt (vector signed char, vector signed char); 5909vector signed int vec_any_lt (vector signed short, 5910 vector unsigned short); 5911vector signed int vec_any_lt (vector unsigned short, 5912 vector signed short); 5913vector signed int vec_any_lt (vector unsigned short, 5914 vector unsigned short); 5915vector signed int vec_any_lt (vector signed short, vector signed short); 5916 5917vector signed int vec_any_lt (vector signed int, vector unsigned int); 5918vector signed int vec_any_lt (vector unsigned int, vector signed int); 5919vector signed int vec_any_lt (vector unsigned int, vector unsigned int); 5920 5921vector signed int vec_any_lt (vector signed int, vector signed int); 5922vector signed int vec_any_lt (vector float, vector float); 5923 5924vector signed int vec_any_nan (vector float); 5925 5926vector signed int vec_any_ne (vector signed char, vector unsigned char); 5927 5928vector signed int vec_any_ne (vector signed char, vector signed char); 5929vector signed int vec_any_ne (vector unsigned char, vector signed char); 5930 5931vector signed int vec_any_ne (vector unsigned char, 5932 vector unsigned char); 5933vector signed int vec_any_ne (vector signed short, 5934 vector unsigned short); 5935vector signed int vec_any_ne (vector signed short, vector signed short); 5936 5937vector signed int vec_any_ne (vector unsigned short, 5938 vector signed short); 5939vector signed int vec_any_ne (vector unsigned short, 5940 vector unsigned short); 5941vector signed int vec_any_ne (vector signed int, vector unsigned int); 5942vector signed int vec_any_ne (vector signed int, vector signed int); 5943vector signed int vec_any_ne (vector unsigned int, vector signed int); 5944vector signed int vec_any_ne (vector unsigned int, vector unsigned int); 5945 5946vector signed int vec_any_ne (vector float, vector float); 5947 5948vector signed int vec_any_nge (vector float, vector float); 5949 5950vector signed int vec_any_ngt (vector float, vector float); 5951 5952vector signed int vec_any_nle (vector float, vector float); 5953 5954vector signed int vec_any_nlt (vector float, vector float); 5955 5956vector signed int vec_any_numeric (vector float); 5957 5958vector signed int vec_any_out (vector float, vector float); 5959@end smallexample 5960 5961@node Pragmas 5962@section Pragmas Accepted by GCC 5963@cindex pragmas 5964@cindex #pragma 5965 5966GCC supports several types of pragmas, primarily in order to compile 5967code originally written for other compilers. Note that in general 5968we do not recommend the use of pragmas; @xref{Function Attributes}, 5969for further explanation. 5970 5971@menu 5972* ARM Pragmas:: 5973* Darwin Pragmas:: 5974* Solaris Pragmas:: 5975* Tru64 Pragmas:: 5976@end menu 5977 5978@node ARM Pragmas 5979@subsection ARM Pragmas 5980 5981The ARM target defines pragmas for controlling the default addition of 5982@code{long_call} and @code{short_call} attributes to functions. 5983@xref{Function Attributes}, for information about the effects of these 5984attributes. 5985 5986@table @code 5987@item long_calls 5988@cindex pragma, long_calls 5989Set all subsequent functions to have the @code{long_call} attribute. 5990 5991@item no_long_calls 5992@cindex pragma, no_long_calls 5993Set all subsequent functions to have the @code{short_call} attribute. 5994 5995@item long_calls_off 5996@cindex pragma, long_calls_off 5997Do not affect the @code{long_call} or @code{short_call} attributes of 5998subsequent functions. 5999@end table 6000 6001@c Describe c4x pragmas here. 6002@c Describe h8300 pragmas here. 6003@c Describe i370 pragmas here. 6004@c Describe i960 pragmas here. 6005@c Describe sh pragmas here. 6006@c Describe v850 pragmas here. 6007 6008@node Darwin Pragmas 6009@subsection Darwin Pragmas 6010 6011The following pragmas are available for all architectures running the 6012Darwin operating system. These are useful for compatibility with other 6013MacOS compilers. 6014 6015@table @code 6016@item mark @var{tokens}@dots{} 6017@cindex pragma, mark 6018This pragma is accepted, but has no effect. 6019 6020@item options align=@var{alignment} 6021@cindex pragma, options align 6022This pragma sets the alignment of fields in structures. The values of 6023@var{alignment} may be @code{mac68k}, to emulate m68k alignment, or 6024@code{power}, to emulate PowerPC alignment. Uses of this pragma nest 6025properly; to restore the previous setting, use @code{reset} for the 6026@var{alignment}. 6027 6028@item segment @var{tokens}@dots{} 6029@cindex pragma, segment 6030This pragma is accepted, but has no effect. 6031 6032@item unused (@var{var} [, @var{var}]@dots{}) 6033@cindex pragma, unused 6034This pragma declares variables to be possibly unused. GCC will not 6035produce warnings for the listed variables. The effect is similar to 6036that of the @code{unused} attribute, except that this pragma may appear 6037anywhere within the variables' scopes. 6038@end table 6039 6040@node Solaris Pragmas 6041@subsection Solaris Pragmas 6042 6043For compatibility with the SunPRO compiler, the following pragma 6044is supported. 6045 6046@table @code 6047@item redefine_extname @var{oldname} @var{newname} 6048@cindex pragma, redefine_extname 6049 6050This pragma gives the C function @var{oldname} the assembler label 6051@var{newname}. The pragma must appear before the function declaration. 6052This pragma is equivalent to the asm labels extension (@pxref{Asm 6053Labels}). The preprocessor defines @code{__PRAGMA_REDEFINE_EXTNAME} 6054if the pragma is available. 6055@end table 6056 6057@node Tru64 Pragmas 6058@subsection Tru64 Pragmas 6059 6060For compatibility with the Compaq C compiler, the following pragma 6061is supported. 6062 6063@table @code 6064@item extern_prefix @var{string} 6065@cindex pragma, extern_prefix 6066 6067This pragma renames all subsequent function and variable declarations 6068such that @var{string} is prepended to the name. This effect may be 6069terminated by using another @code{extern_prefix} pragma with the 6070empty string. 6071 6072This pragma is similar in intent to to the asm labels extension 6073(@pxref{Asm Labels}) in that the system programmer wants to change 6074the assembly-level ABI without changing the source-level API. The 6075preprocessor defines @code{__EXTERN_PREFIX} if the pragma is available. 6076@end table 6077 6078@node Unnamed Fields 6079@section Unnamed struct/union fields within structs/unions. 6080@cindex struct 6081@cindex union 6082 6083For compatibility with other compilers, GCC allows you to define 6084a structure or union that contains, as fields, structures and unions 6085without names. For example: 6086 6087@example 6088struct @{ 6089 int a; 6090 union @{ 6091 int b; 6092 float c; 6093 @}; 6094 int d; 6095@} foo; 6096@end example 6097 6098In this example, the user would be able to access members of the unnamed 6099union with code like @samp{foo.b}. Note that only unnamed structs and 6100unions are allowed, you may not have, for example, an unnamed 6101@code{int}. 6102 6103You must never create such structures that cause ambiguous field definitions. 6104For example, this structure: 6105 6106@example 6107struct @{ 6108 int a; 6109 struct @{ 6110 int a; 6111 @}; 6112@} foo; 6113@end example 6114 6115It is ambiguous which @code{a} is being referred to with @samp{foo.a}. 6116Such constructs are not supported and must be avoided. In the future, 6117such constructs may be detected and treated as compilation errors. 6118 6119@node C++ Extensions 6120@chapter Extensions to the C++ Language 6121@cindex extensions, C++ language 6122@cindex C++ language extensions 6123 6124The GNU compiler provides these extensions to the C++ language (and you 6125can also use most of the C language extensions in your C++ programs). If you 6126want to write code that checks whether these features are available, you can 6127test for the GNU compiler the same way as for C programs: check for a 6128predefined macro @code{__GNUC__}. You can also use @code{__GNUG__} to 6129test specifically for GNU C++ (@pxref{Standard Predefined,,Standard 6130Predefined Macros,cpp.info,The C Preprocessor}). 6131 6132@menu 6133* Min and Max:: C++ Minimum and maximum operators. 6134* Volatiles:: What constitutes an access to a volatile object. 6135* Restricted Pointers:: C99 restricted pointers and references. 6136* Vague Linkage:: Where G++ puts inlines, vtables and such. 6137* C++ Interface:: You can use a single C++ header file for both 6138 declarations and definitions. 6139* Template Instantiation:: Methods for ensuring that exactly one copy of 6140 each needed template instantiation is emitted. 6141* Bound member functions:: You can extract a function pointer to the 6142 method denoted by a @samp{->*} or @samp{.*} expression. 6143* C++ Attributes:: Variable, function, and type attributes for C++ only. 6144* Java Exceptions:: Tweaking exception handling to work with Java. 6145* Deprecated Features:: Things might disappear from g++. 6146* Backwards Compatibility:: Compatibilities with earlier definitions of C++. 6147@end menu 6148 6149@node Min and Max 6150@section Minimum and Maximum Operators in C++ 6151 6152It is very convenient to have operators which return the ``minimum'' or the 6153``maximum'' of two arguments. In GNU C++ (but not in GNU C), 6154 6155@table @code 6156@item @var{a} <? @var{b} 6157@findex <? 6158@cindex minimum operator 6159is the @dfn{minimum}, returning the smaller of the numeric values 6160@var{a} and @var{b}; 6161 6162@item @var{a} >? @var{b} 6163@findex >? 6164@cindex maximum operator 6165is the @dfn{maximum}, returning the larger of the numeric values @var{a} 6166and @var{b}. 6167@end table 6168 6169These operations are not primitive in ordinary C++, since you can 6170use a macro to return the minimum of two things in C++, as in the 6171following example. 6172 6173@example 6174#define MIN(X,Y) ((X) < (Y) ? : (X) : (Y)) 6175@end example 6176 6177@noindent 6178You might then use @w{@samp{int min = MIN (i, j);}} to set @var{min} to 6179the minimum value of variables @var{i} and @var{j}. 6180 6181However, side effects in @code{X} or @code{Y} may cause unintended 6182behavior. For example, @code{MIN (i++, j++)} will fail, incrementing 6183the smaller counter twice. The GNU C @code{typeof} extension allows you 6184to write safe macros that avoid this kind of problem (@pxref{Typeof}). 6185However, writing @code{MIN} and @code{MAX} as macros also forces you to 6186use function-call notation for a fundamental arithmetic operation. 6187Using GNU C++ extensions, you can write @w{@samp{int min = i <? j;}} 6188instead. 6189 6190Since @code{<?} and @code{>?} are built into the compiler, they properly 6191handle expressions with side-effects; @w{@samp{int min = i++ <? j++;}} 6192works correctly. 6193 6194@node Volatiles 6195@section When is a Volatile Object Accessed? 6196@cindex accessing volatiles 6197@cindex volatile read 6198@cindex volatile write 6199@cindex volatile access 6200 6201Both the C and C++ standard have the concept of volatile objects. These 6202are normally accessed by pointers and used for accessing hardware. The 6203standards encourage compilers to refrain from optimizations 6204concerning accesses to volatile objects that it might perform on 6205non-volatile objects. The C standard leaves it implementation defined 6206as to what constitutes a volatile access. The C++ standard omits to 6207specify this, except to say that C++ should behave in a similar manner 6208to C with respect to volatiles, where possible. The minimum either 6209standard specifies is that at a sequence point all previous accesses to 6210volatile objects have stabilized and no subsequent accesses have 6211occurred. Thus an implementation is free to reorder and combine 6212volatile accesses which occur between sequence points, but cannot do so 6213for accesses across a sequence point. The use of volatiles does not 6214allow you to violate the restriction on updating objects multiple times 6215within a sequence point. 6216 6217In most expressions, it is intuitively obvious what is a read and what is 6218a write. For instance 6219 6220@example 6221volatile int *dst = @var{somevalue}; 6222volatile int *src = @var{someothervalue}; 6223*dst = *src; 6224@end example 6225 6226@noindent 6227will cause a read of the volatile object pointed to by @var{src} and stores the 6228value into the volatile object pointed to by @var{dst}. There is no 6229guarantee that these reads and writes are atomic, especially for objects 6230larger than @code{int}. 6231 6232Less obvious expressions are where something which looks like an access 6233is used in a void context. An example would be, 6234 6235@example 6236volatile int *src = @var{somevalue}; 6237*src; 6238@end example 6239 6240With C, such expressions are rvalues, and as rvalues cause a read of 6241the object, GCC interprets this as a read of the volatile being pointed 6242to. The C++ standard specifies that such expressions do not undergo 6243lvalue to rvalue conversion, and that the type of the dereferenced 6244object may be incomplete. The C++ standard does not specify explicitly 6245that it is this lvalue to rvalue conversion which is responsible for 6246causing an access. However, there is reason to believe that it is, 6247because otherwise certain simple expressions become undefined. However, 6248because it would surprise most programmers, G++ treats dereferencing a 6249pointer to volatile object of complete type in a void context as a read 6250of the object. When the object has incomplete type, G++ issues a 6251warning. 6252 6253@example 6254struct S; 6255struct T @{int m;@}; 6256volatile S *ptr1 = @var{somevalue}; 6257volatile T *ptr2 = @var{somevalue}; 6258*ptr1; 6259*ptr2; 6260@end example 6261 6262In this example, a warning is issued for @code{*ptr1}, and @code{*ptr2} 6263causes a read of the object pointed to. If you wish to force an error on 6264the first case, you must force a conversion to rvalue with, for instance 6265a static cast, @code{static_cast<S>(*ptr1)}. 6266 6267When using a reference to volatile, G++ does not treat equivalent 6268expressions as accesses to volatiles, but instead issues a warning that 6269no volatile is accessed. The rationale for this is that otherwise it 6270becomes difficult to determine where volatile access occur, and not 6271possible to ignore the return value from functions returning volatile 6272references. Again, if you wish to force a read, cast the reference to 6273an rvalue. 6274 6275@node Restricted Pointers 6276@section Restricting Pointer Aliasing 6277@cindex restricted pointers 6278@cindex restricted references 6279@cindex restricted this pointer 6280 6281As with gcc, g++ understands the C99 feature of restricted pointers, 6282specified with the @code{__restrict__}, or @code{__restrict} type 6283qualifier. Because you cannot compile C++ by specifying the @option{-std=c99} 6284language flag, @code{restrict} is not a keyword in C++. 6285 6286In addition to allowing restricted pointers, you can specify restricted 6287references, which indicate that the reference is not aliased in the local 6288context. 6289 6290@example 6291void fn (int *__restrict__ rptr, int &__restrict__ rref) 6292@{ 6293 @dots{} 6294@} 6295@end example 6296 6297@noindent 6298In the body of @code{fn}, @var{rptr} points to an unaliased integer and 6299@var{rref} refers to a (different) unaliased integer. 6300 6301You may also specify whether a member function's @var{this} pointer is 6302unaliased by using @code{__restrict__} as a member function qualifier. 6303 6304@example 6305void T::fn () __restrict__ 6306@{ 6307 @dots{} 6308@} 6309@end example 6310 6311@noindent 6312Within the body of @code{T::fn}, @var{this} will have the effective 6313definition @code{T *__restrict__ const this}. Notice that the 6314interpretation of a @code{__restrict__} member function qualifier is 6315different to that of @code{const} or @code{volatile} qualifier, in that it 6316is applied to the pointer rather than the object. This is consistent with 6317other compilers which implement restricted pointers. 6318 6319As with all outermost parameter qualifiers, @code{__restrict__} is 6320ignored in function definition matching. This means you only need to 6321specify @code{__restrict__} in a function definition, rather than 6322in a function prototype as well. 6323 6324@node Vague Linkage 6325@section Vague Linkage 6326@cindex vague linkage 6327 6328There are several constructs in C++ which require space in the object 6329file but are not clearly tied to a single translation unit. We say that 6330these constructs have ``vague linkage''. Typically such constructs are 6331emitted wherever they are needed, though sometimes we can be more 6332clever. 6333 6334@table @asis 6335@item Inline Functions 6336Inline functions are typically defined in a header file which can be 6337included in many different compilations. Hopefully they can usually be 6338inlined, but sometimes an out-of-line copy is necessary, if the address 6339of the function is taken or if inlining fails. In general, we emit an 6340out-of-line copy in all translation units where one is needed. As an 6341exception, we only emit inline virtual functions with the vtable, since 6342it will always require a copy. 6343 6344Local static variables and string constants used in an inline function 6345are also considered to have vague linkage, since they must be shared 6346between all inlined and out-of-line instances of the function. 6347 6348@item VTables 6349@cindex vtable 6350C++ virtual functions are implemented in most compilers using a lookup 6351table, known as a vtable. The vtable contains pointers to the virtual 6352functions provided by a class, and each object of the class contains a 6353pointer to its vtable (or vtables, in some multiple-inheritance 6354situations). If the class declares any non-inline, non-pure virtual 6355functions, the first one is chosen as the ``key method'' for the class, 6356and the vtable is only emitted in the translation unit where the key 6357method is defined. 6358 6359@emph{Note:} If the chosen key method is later defined as inline, the 6360vtable will still be emitted in every translation unit which defines it. 6361Make sure that any inline virtuals are declared inline in the class 6362body, even if they are not defined there. 6363 6364@item type_info objects 6365@cindex type_info 6366@cindex RTTI 6367C++ requires information about types to be written out in order to 6368implement @samp{dynamic_cast}, @samp{typeid} and exception handling. 6369For polymorphic classes (classes with virtual functions), the type_info 6370object is written out along with the vtable so that @samp{dynamic_cast} 6371can determine the dynamic type of a class object at runtime. For all 6372other types, we write out the type_info object when it is used: when 6373applying @samp{typeid} to an expression, throwing an object, or 6374referring to a type in a catch clause or exception specification. 6375 6376@item Template Instantiations 6377Most everything in this section also applies to template instantiations, 6378but there are other options as well. 6379@xref{Template Instantiation,,Where's the Template?}. 6380 6381@end table 6382 6383When used with GNU ld version 2.8 or later on an ELF system such as 6384Linux/GNU or Solaris 2, or on Microsoft Windows, duplicate copies of 6385these constructs will be discarded at link time. This is known as 6386COMDAT support. 6387 6388On targets that don't support COMDAT, but do support weak symbols, GCC 6389will use them. This way one copy will override all the others, but 6390the unused copies will still take up space in the executable. 6391 6392For targets which do not support either COMDAT or weak symbols, 6393most entities with vague linkage will be emitted as local symbols to 6394avoid duplicate definition errors from the linker. This will not happen 6395for local statics in inlines, however, as having multiple copies will 6396almost certainly break things. 6397 6398@xref{C++ Interface,,Declarations and Definitions in One Header}, for 6399another way to control placement of these constructs. 6400 6401@node C++ Interface 6402@section Declarations and Definitions in One Header 6403 6404@cindex interface and implementation headers, C++ 6405@cindex C++ interface and implementation headers 6406C++ object definitions can be quite complex. In principle, your source 6407code will need two kinds of things for each object that you use across 6408more than one source file. First, you need an @dfn{interface} 6409specification, describing its structure with type declarations and 6410function prototypes. Second, you need the @dfn{implementation} itself. 6411It can be tedious to maintain a separate interface description in a 6412header file, in parallel to the actual implementation. It is also 6413dangerous, since separate interface and implementation definitions may 6414not remain parallel. 6415 6416@cindex pragmas, interface and implementation 6417With GNU C++, you can use a single header file for both purposes. 6418 6419@quotation 6420@emph{Warning:} The mechanism to specify this is in transition. For the 6421nonce, you must use one of two @code{#pragma} commands; in a future 6422release of GNU C++, an alternative mechanism will make these 6423@code{#pragma} commands unnecessary. 6424@end quotation 6425 6426The header file contains the full definitions, but is marked with 6427@samp{#pragma interface} in the source code. This allows the compiler 6428to use the header file only as an interface specification when ordinary 6429source files incorporate it with @code{#include}. In the single source 6430file where the full implementation belongs, you can use either a naming 6431convention or @samp{#pragma implementation} to indicate this alternate 6432use of the header file. 6433 6434@table @code 6435@item #pragma interface 6436@itemx #pragma interface "@var{subdir}/@var{objects}.h" 6437@kindex #pragma interface 6438Use this directive in @emph{header files} that define object classes, to save 6439space in most of the object files that use those classes. Normally, 6440local copies of certain information (backup copies of inline member 6441functions, debugging information, and the internal tables that implement 6442virtual functions) must be kept in each object file that includes class 6443definitions. You can use this pragma to avoid such duplication. When a 6444header file containing @samp{#pragma interface} is included in a 6445compilation, this auxiliary information will not be generated (unless 6446the main input source file itself uses @samp{#pragma implementation}). 6447Instead, the object files will contain references to be resolved at link 6448time. 6449 6450The second form of this directive is useful for the case where you have 6451multiple headers with the same name in different directories. If you 6452use this form, you must specify the same string to @samp{#pragma 6453implementation}. 6454 6455@item #pragma implementation 6456@itemx #pragma implementation "@var{objects}.h" 6457@kindex #pragma implementation 6458Use this pragma in a @emph{main input file}, when you want full output from 6459included header files to be generated (and made globally visible). The 6460included header file, in turn, should use @samp{#pragma interface}. 6461Backup copies of inline member functions, debugging information, and the 6462internal tables used to implement virtual functions are all generated in 6463implementation files. 6464 6465@cindex implied @code{#pragma implementation} 6466@cindex @code{#pragma implementation}, implied 6467@cindex naming convention, implementation headers 6468If you use @samp{#pragma implementation} with no argument, it applies to 6469an include file with the same basename@footnote{A file's @dfn{basename} 6470was the name stripped of all leading path information and of trailing 6471suffixes, such as @samp{.h} or @samp{.C} or @samp{.cc}.} as your source 6472file. For example, in @file{allclass.cc}, giving just 6473@samp{#pragma implementation} 6474by itself is equivalent to @samp{#pragma implementation "allclass.h"}. 6475 6476In versions of GNU C++ prior to 2.6.0 @file{allclass.h} was treated as 6477an implementation file whenever you would include it from 6478@file{allclass.cc} even if you never specified @samp{#pragma 6479implementation}. This was deemed to be more trouble than it was worth, 6480however, and disabled. 6481 6482If you use an explicit @samp{#pragma implementation}, it must appear in 6483your source file @emph{before} you include the affected header files. 6484 6485Use the string argument if you want a single implementation file to 6486include code from multiple header files. (You must also use 6487@samp{#include} to include the header file; @samp{#pragma 6488implementation} only specifies how to use the file---it doesn't actually 6489include it.) 6490 6491There is no way to split up the contents of a single header file into 6492multiple implementation files. 6493@end table 6494 6495@cindex inlining and C++ pragmas 6496@cindex C++ pragmas, effect on inlining 6497@cindex pragmas in C++, effect on inlining 6498@samp{#pragma implementation} and @samp{#pragma interface} also have an 6499effect on function inlining. 6500 6501If you define a class in a header file marked with @samp{#pragma 6502interface}, the effect on a function defined in that class is similar to 6503an explicit @code{extern} declaration---the compiler emits no code at 6504all to define an independent version of the function. Its definition 6505is used only for inlining with its callers. 6506 6507@opindex fno-implement-inlines 6508Conversely, when you include the same header file in a main source file 6509that declares it as @samp{#pragma implementation}, the compiler emits 6510code for the function itself; this defines a version of the function 6511that can be found via pointers (or by callers compiled without 6512inlining). If all calls to the function can be inlined, you can avoid 6513emitting the function by compiling with @option{-fno-implement-inlines}. 6514If any calls were not inlined, you will get linker errors. 6515 6516@node Template Instantiation 6517@section Where's the Template? 6518 6519@cindex template instantiation 6520 6521C++ templates are the first language feature to require more 6522intelligence from the environment than one usually finds on a UNIX 6523system. Somehow the compiler and linker have to make sure that each 6524template instance occurs exactly once in the executable if it is needed, 6525and not at all otherwise. There are two basic approaches to this 6526problem, which I will refer to as the Borland model and the Cfront model. 6527 6528@table @asis 6529@item Borland model 6530Borland C++ solved the template instantiation problem by adding the code 6531equivalent of common blocks to their linker; the compiler emits template 6532instances in each translation unit that uses them, and the linker 6533collapses them together. The advantage of this model is that the linker 6534only has to consider the object files themselves; there is no external 6535complexity to worry about. This disadvantage is that compilation time 6536is increased because the template code is being compiled repeatedly. 6537Code written for this model tends to include definitions of all 6538templates in the header file, since they must be seen to be 6539instantiated. 6540 6541@item Cfront model 6542The AT&T C++ translator, Cfront, solved the template instantiation 6543problem by creating the notion of a template repository, an 6544automatically maintained place where template instances are stored. A 6545more modern version of the repository works as follows: As individual 6546object files are built, the compiler places any template definitions and 6547instantiations encountered in the repository. At link time, the link 6548wrapper adds in the objects in the repository and compiles any needed 6549instances that were not previously emitted. The advantages of this 6550model are more optimal compilation speed and the ability to use the 6551system linker; to implement the Borland model a compiler vendor also 6552needs to replace the linker. The disadvantages are vastly increased 6553complexity, and thus potential for error; for some code this can be 6554just as transparent, but in practice it can been very difficult to build 6555multiple programs in one directory and one program in multiple 6556directories. Code written for this model tends to separate definitions 6557of non-inline member templates into a separate file, which should be 6558compiled separately. 6559@end table 6560 6561When used with GNU ld version 2.8 or later on an ELF system such as 6562Linux/GNU or Solaris 2, or on Microsoft Windows, g++ supports the 6563Borland model. On other systems, g++ implements neither automatic 6564model. 6565 6566A future version of g++ will support a hybrid model whereby the compiler 6567will emit any instantiations for which the template definition is 6568included in the compile, and store template definitions and 6569instantiation context information into the object file for the rest. 6570The link wrapper will extract that information as necessary and invoke 6571the compiler to produce the remaining instantiations. The linker will 6572then combine duplicate instantiations. 6573 6574In the mean time, you have the following options for dealing with 6575template instantiations: 6576 6577@enumerate 6578@item 6579@opindex frepo 6580Compile your template-using code with @option{-frepo}. The compiler will 6581generate files with the extension @samp{.rpo} listing all of the 6582template instantiations used in the corresponding object files which 6583could be instantiated there; the link wrapper, @samp{collect2}, will 6584then update the @samp{.rpo} files to tell the compiler where to place 6585those instantiations and rebuild any affected object files. The 6586link-time overhead is negligible after the first pass, as the compiler 6587will continue to place the instantiations in the same files. 6588 6589This is your best option for application code written for the Borland 6590model, as it will just work. Code written for the Cfront model will 6591need to be modified so that the template definitions are available at 6592one or more points of instantiation; usually this is as simple as adding 6593@code{#include <tmethods.cc>} to the end of each template header. 6594 6595For library code, if you want the library to provide all of the template 6596instantiations it needs, just try to link all of its object files 6597together; the link will fail, but cause the instantiations to be 6598generated as a side effect. Be warned, however, that this may cause 6599conflicts if multiple libraries try to provide the same instantiations. 6600For greater control, use explicit instantiation as described in the next 6601option. 6602 6603@item 6604@opindex fno-implicit-templates 6605Compile your code with @option{-fno-implicit-templates} to disable the 6606implicit generation of template instances, and explicitly instantiate 6607all the ones you use. This approach requires more knowledge of exactly 6608which instances you need than do the others, but it's less 6609mysterious and allows greater control. You can scatter the explicit 6610instantiations throughout your program, perhaps putting them in the 6611translation units where the instances are used or the translation units 6612that define the templates themselves; you can put all of the explicit 6613instantiations you need into one big file; or you can create small files 6614like 6615 6616@example 6617#include "Foo.h" 6618#include "Foo.cc" 6619 6620template class Foo<int>; 6621template ostream& operator << 6622 (ostream&, const Foo<int>&); 6623@end example 6624 6625for each of the instances you need, and create a template instantiation 6626library from those. 6627 6628If you are using Cfront-model code, you can probably get away with not 6629using @option{-fno-implicit-templates} when compiling files that don't 6630@samp{#include} the member template definitions. 6631 6632If you use one big file to do the instantiations, you may want to 6633compile it without @option{-fno-implicit-templates} so you get all of the 6634instances required by your explicit instantiations (but not by any 6635other files) without having to specify them as well. 6636 6637g++ has extended the template instantiation syntax outlined in the 6638Working Paper to allow forward declaration of explicit instantiations 6639(with @code{extern}), instantiation of the compiler support data for a 6640template class (i.e.@: the vtable) without instantiating any of its 6641members (with @code{inline}), and instantiation of only the static data 6642members of a template class, without the support data or member 6643functions (with (@code{static}): 6644 6645@example 6646extern template int max (int, int); 6647inline template class Foo<int>; 6648static template class Foo<int>; 6649@end example 6650 6651@item 6652Do nothing. Pretend g++ does implement automatic instantiation 6653management. Code written for the Borland model will work fine, but 6654each translation unit will contain instances of each of the templates it 6655uses. In a large program, this can lead to an unacceptable amount of code 6656duplication. 6657 6658@item 6659@opindex fexternal-templates 6660Add @samp{#pragma interface} to all files containing template 6661definitions. For each of these files, add @samp{#pragma implementation 6662"@var{filename}"} to the top of some @samp{.C} file which 6663@samp{#include}s it. Then compile everything with 6664@option{-fexternal-templates}. The templates will then only be expanded 6665in the translation unit which implements them (i.e.@: has a @samp{#pragma 6666implementation} line for the file where they live); all other files will 6667use external references. If you're lucky, everything should work 6668properly. If you get undefined symbol errors, you need to make sure 6669that each template instance which is used in the program is used in the 6670file which implements that template. If you don't have any use for a 6671particular instance in that file, you can just instantiate it 6672explicitly, using the syntax from the latest C++ working paper: 6673 6674@example 6675template class A<int>; 6676template ostream& operator << (ostream&, const A<int>&); 6677@end example 6678 6679This strategy will work with code written for either model. If you are 6680using code written for the Cfront model, the file containing a class 6681template and the file containing its member templates should be 6682implemented in the same translation unit. 6683 6684@item 6685@opindex falt-external-templates 6686A slight variation on this approach is to use the flag 6687@option{-falt-external-templates} instead. This flag causes template 6688instances to be emitted in the translation unit that implements the 6689header where they are first instantiated, rather than the one which 6690implements the file where the templates are defined. This header must 6691be the same in all translation units, or things are likely to break. 6692 6693@xref{C++ Interface,,Declarations and Definitions in One Header}, for 6694more discussion of these pragmas. 6695@end enumerate 6696 6697@node Bound member functions 6698@section Extracting the function pointer from a bound pointer to member function 6699 6700@cindex pmf 6701@cindex pointer to member function 6702@cindex bound pointer to member function 6703 6704In C++, pointer to member functions (PMFs) are implemented using a wide 6705pointer of sorts to handle all the possible call mechanisms; the PMF 6706needs to store information about how to adjust the @samp{this} pointer, 6707and if the function pointed to is virtual, where to find the vtable, and 6708where in the vtable to look for the member function. If you are using 6709PMFs in an inner loop, you should really reconsider that decision. If 6710that is not an option, you can extract the pointer to the function that 6711would be called for a given object/PMF pair and call it directly inside 6712the inner loop, to save a bit of time. 6713 6714Note that you will still be paying the penalty for the call through a 6715function pointer; on most modern architectures, such a call defeats the 6716branch prediction features of the CPU@. This is also true of normal 6717virtual function calls. 6718 6719The syntax for this extension is 6720 6721@example 6722extern A a; 6723extern int (A::*fp)(); 6724typedef int (*fptr)(A *); 6725 6726fptr p = (fptr)(a.*fp); 6727@end example 6728 6729For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}), 6730no object is needed to obtain the address of the function. They can be 6731converted to function pointers directly: 6732 6733@example 6734fptr p1 = (fptr)(&A::foo); 6735@end example 6736 6737@opindex Wno-pmf-conversions 6738You must specify @option{-Wno-pmf-conversions} to use this extension. 6739 6740@node C++ Attributes 6741@section C++-Specific Variable, Function, and Type Attributes 6742 6743Some attributes only make sense for C++ programs. 6744 6745@table @code 6746@item init_priority (@var{priority}) 6747@cindex init_priority attribute 6748 6749 6750In Standard C++, objects defined at namespace scope are guaranteed to be 6751initialized in an order in strict accordance with that of their definitions 6752@emph{in a given translation unit}. No guarantee is made for initializations 6753across translation units. However, GNU C++ allows users to control the 6754order of initialization of objects defined at namespace scope with the 6755@code{init_priority} attribute by specifying a relative @var{priority}, 6756a constant integral expression currently bounded between 101 and 65535 6757inclusive. Lower numbers indicate a higher priority. 6758 6759In the following example, @code{A} would normally be created before 6760@code{B}, but the @code{init_priority} attribute has reversed that order: 6761 6762@smallexample 6763Some_Class A __attribute__ ((init_priority (2000))); 6764Some_Class B __attribute__ ((init_priority (543))); 6765@end smallexample 6766 6767@noindent 6768Note that the particular values of @var{priority} do not matter; only their 6769relative ordering. 6770 6771@item java_interface 6772@cindex java_interface attribute 6773 6774This type attribute informs C++ that the class is a Java interface. It may 6775only be applied to classes declared within an @code{extern "Java"} block. 6776Calls to methods declared in this interface will be dispatched using GCJ's 6777interface table mechanism, instead of regular virtual table dispatch. 6778 6779@end table 6780 6781@node Java Exceptions 6782@section Java Exceptions 6783 6784The Java language uses a slightly different exception handling model 6785from C++. Normally, GNU C++ will automatically detect when you are 6786writing C++ code that uses Java exceptions, and handle them 6787appropriately. However, if C++ code only needs to execute destructors 6788when Java exceptions are thrown through it, GCC will guess incorrectly. 6789Sample problematic code is: 6790 6791@smallexample 6792 struct S @{ ~S(); @}; 6793 extern void bar(); // is written in Java, and may throw exceptions 6794 void foo() 6795 @{ 6796 S s; 6797 bar(); 6798 @} 6799@end smallexample 6800 6801@noindent 6802The usual effect of an incorrect guess is a link failure, complaining of 6803a missing routine called @samp{__gxx_personality_v0}. 6804 6805You can inform the compiler that Java exceptions are to be used in a 6806translation unit, irrespective of what it might think, by writing 6807@samp{@w{#pragma GCC java_exceptions}} at the head of the file. This 6808@samp{#pragma} must appear before any functions that throw or catch 6809exceptions, or run destructors when exceptions are thrown through them. 6810 6811You cannot mix Java and C++ exceptions in the same translation unit. It 6812is believed to be safe to throw a C++ exception from one file through 6813another file compiled for the Java exception model, or vice versa, but 6814there may be bugs in this area. 6815 6816@node Deprecated Features 6817@section Deprecated Features 6818 6819In the past, the GNU C++ compiler was extended to experiment with new 6820features, at a time when the C++ language was still evolving. Now that 6821the C++ standard is complete, some of those features are superseded by 6822superior alternatives. Using the old features might cause a warning in 6823some cases that the feature will be dropped in the future. In other 6824cases, the feature might be gone already. 6825 6826While the list below is not exhaustive, it documents some of the options 6827that are now deprecated: 6828 6829@table @code 6830@item -fexternal-templates 6831@itemx -falt-external-templates 6832These are two of the many ways for g++ to implement template 6833instantiation. @xref{Template Instantiation}. The C++ standard clearly 6834defines how template definitions have to be organized across 6835implementation units. g++ has an implicit instantiation mechanism that 6836should work just fine for standard-conforming code. 6837 6838@item -fstrict-prototype 6839@itemx -fno-strict-prototype 6840Previously it was possible to use an empty prototype parameter list to 6841indicate an unspecified number of parameters (like C), rather than no 6842parameters, as C++ demands. This feature has been removed, except where 6843it is required for backwards compatibility @xref{Backwards Compatibility}. 6844@end table 6845 6846The named return value extension has been deprecated, and is now 6847removed from g++. 6848 6849The use of initializer lists with new expressions has been deprecated, 6850and is now removed from g++. 6851 6852Floating and complex non-type template parameters have been deprecated, 6853and are now removed from g++. 6854 6855The implicit typename extension has been deprecated and will be removed 6856from g++ at some point. In some cases g++ determines that a dependant 6857type such as @code{TPL<T>::X} is a type without needing a 6858@code{typename} keyword, contrary to the standard. 6859 6860@node Backwards Compatibility 6861@section Backwards Compatibility 6862@cindex Backwards Compatibility 6863@cindex ARM [Annotated C++ Reference Manual] 6864 6865Now that there is a definitive ISO standard C++, G++ has a specification 6866to adhere to. The C++ language evolved over time, and features that 6867used to be acceptable in previous drafts of the standard, such as the ARM 6868[Annotated C++ Reference Manual], are no longer accepted. In order to allow 6869compilation of C++ written to such drafts, G++ contains some backwards 6870compatibilities. @emph{All such backwards compatibility features are 6871liable to disappear in future versions of G++.} They should be considered 6872deprecated @xref{Deprecated Features}. 6873 6874@table @code 6875@item For scope 6876If a variable is declared at for scope, it used to remain in scope until 6877the end of the scope which contained the for statement (rather than just 6878within the for scope). G++ retains this, but issues a warning, if such a 6879variable is accessed outside the for scope. 6880 6881@item Implicit C language 6882Old C system header files did not contain an @code{extern "C" @{@dots{}@}} 6883scope to set the language. On such systems, all header files are 6884implicitly scoped inside a C language scope. Also, an empty prototype 6885@code{()} will be treated as an unspecified number of arguments, rather 6886than no arguments, as C++ demands. 6887@end table 6888