1 @c Copyright (C) 1988, 1989, 1992, 1993, 1994, 1996, 1998, 1999, 2000, 2001,
2 @c 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 @c Free Software Foundation, Inc.
5 @c This is part of the GCC manual.
6 @c For copying conditions, see the file gcc.texi.
9 @chapter Extensions to the C Language Family
10 @cindex extensions, C language
11 @cindex C language extensions
14 GNU C provides several language features not found in ISO standard C@.
15 (The @option{-pedantic} option directs GCC to print a warning message if
16 any of these features is used.) To test for the availability of these
17 features in conditional compilation, check for a predefined macro
18 @code{__GNUC__}, which is always defined under GCC@.
20 These extensions are available in C and Objective-C@. Most of them are
21 also available in C++. @xref{C++ Extensions,,Extensions to the
22 C++ Language}, for extensions that apply @emph{only} to C++.
24 Some features that are in ISO C99 but not C89 or C++ are also, as
25 extensions, accepted by GCC in C89 mode and in C++.
28 * Statement Exprs:: Putting statements and declarations inside expressions.
29 * Local Labels:: Labels local to a block.
30 * Labels as Values:: Getting pointers to labels, and computed gotos.
31 * Nested Functions:: As in Algol and Pascal, lexical scoping of functions.
32 * Constructing Calls:: Dispatching a call to another function.
33 * Typeof:: @code{typeof}: referring to the type of an expression.
34 * Conditionals:: Omitting the middle operand of a @samp{?:} expression.
35 * Long Long:: Double-word integers---@code{long long int}.
36 * Complex:: Data types for complex numbers.
37 * Floating Types:: Additional Floating Types.
38 * Half-Precision:: Half-Precision Floating Point.
39 * Decimal Float:: Decimal Floating Types.
40 * Hex Floats:: Hexadecimal floating-point constants.
41 * Fixed-Point:: Fixed-Point Types.
42 * Named Address Spaces::Named address spaces.
43 * Zero Length:: Zero-length arrays.
44 * Variable Length:: Arrays whose length is computed at run time.
45 * Empty Structures:: Structures with no members.
46 * Variadic Macros:: Macros with a variable number of arguments.
47 * Escaped Newlines:: Slightly looser rules for escaped newlines.
48 * Subscripting:: Any array can be subscripted, even if not an lvalue.
49 * Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers.
50 * Initializers:: Non-constant initializers.
51 * Compound Literals:: Compound literals give structures, unions
53 * Designated Inits:: Labeling elements of initializers.
54 * Cast to Union:: Casting to union type from any member of the union.
55 * Case Ranges:: `case 1 ... 9' and such.
56 * Mixed Declarations:: Mixing declarations and code.
57 * Function Attributes:: Declaring that functions have no side effects,
58 or that they can never return.
59 * Attribute Syntax:: Formal syntax for attributes.
60 * Function Prototypes:: Prototype declarations and old-style definitions.
61 * C++ Comments:: C++ comments are recognized.
62 * Dollar Signs:: Dollar sign is allowed in identifiers.
63 * Character Escapes:: @samp{\e} stands for the character @key{ESC}.
64 * Variable Attributes:: Specifying attributes of variables.
65 * Type Attributes:: Specifying attributes of types.
66 * Alignment:: Inquiring about the alignment of a type or variable.
67 * Inline:: Defining inline functions (as fast as macros).
68 * Extended Asm:: Assembler instructions with C expressions as operands.
69 (With them you can define ``built-in'' functions.)
70 * Constraints:: Constraints for asm operands
71 * Asm Labels:: Specifying the assembler name to use for a C symbol.
72 * Explicit Reg Vars:: Defining variables residing in specified registers.
73 * Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files.
74 * Incomplete Enums:: @code{enum foo;}, with details to follow.
75 * Function Names:: Printable strings which are the name of the current
77 * Return Address:: Getting the return or frame address of a function.
78 * Vector Extensions:: Using vector instructions through built-in functions.
79 * Offsetof:: Special syntax for implementing @code{offsetof}.
80 * Atomic Builtins:: Built-in functions for atomic memory access.
81 * Object Size Checking:: Built-in functions for limited buffer overflow
83 * Other Builtins:: Other built-in functions.
84 * Target Builtins:: Built-in functions specific to particular targets.
85 * Target Format Checks:: Format checks specific to particular targets.
86 * Pragmas:: Pragmas accepted by GCC.
87 * Unnamed Fields:: Unnamed struct/union fields within structs/unions.
88 * Thread-Local:: Per-thread variables.
89 * Binary constants:: Binary constants using the @samp{0b} prefix.
93 @section Statements and Declarations in Expressions
94 @cindex statements inside expressions
95 @cindex declarations inside expressions
96 @cindex expressions containing statements
97 @cindex macros, statements in expressions
99 @c the above section title wrapped and causes an underfull hbox.. i
100 @c changed it from "within" to "in". --mew 4feb93
101 A compound statement enclosed in parentheses may appear as an expression
102 in GNU C@. This allows you to use loops, switches, and local variables
103 within an expression.
105 Recall that a compound statement is a sequence of statements surrounded
106 by braces; in this construct, parentheses go around the braces. For
110 (@{ int y = foo (); int z;
117 is a valid (though slightly more complex than necessary) expression
118 for the absolute value of @code{foo ()}.
120 The last thing in the compound statement should be an expression
121 followed by a semicolon; the value of this subexpression serves as the
122 value of the entire construct. (If you use some other kind of statement
123 last within the braces, the construct has type @code{void}, and thus
124 effectively no value.)
126 This feature is especially useful in making macro definitions ``safe'' (so
127 that they evaluate each operand exactly once). For example, the
128 ``maximum'' function is commonly defined as a macro in standard C as
132 #define max(a,b) ((a) > (b) ? (a) : (b))
136 @cindex side effects, macro argument
137 But this definition computes either @var{a} or @var{b} twice, with bad
138 results if the operand has side effects. In GNU C, if you know the
139 type of the operands (here taken as @code{int}), you can define
140 the macro safely as follows:
143 #define maxint(a,b) \
144 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
147 Embedded statements are not allowed in constant expressions, such as
148 the value of an enumeration constant, the width of a bit-field, or
149 the initial value of a static variable.
151 If you don't know the type of the operand, you can still do this, but you
152 must use @code{typeof} (@pxref{Typeof}).
154 In G++, the result value of a statement expression undergoes array and
155 function pointer decay, and is returned by value to the enclosing
156 expression. For instance, if @code{A} is a class, then
165 will construct a temporary @code{A} object to hold the result of the
166 statement expression, and that will be used to invoke @code{Foo}.
167 Therefore the @code{this} pointer observed by @code{Foo} will not be the
170 Any temporaries created within a statement within a statement expression
171 will be destroyed at the statement's end. This makes statement
172 expressions inside macros slightly different from function calls. In
173 the latter case temporaries introduced during argument evaluation will
174 be destroyed at the end of the statement that includes the function
175 call. In the statement expression case they will be destroyed during
176 the statement expression. For instance,
179 #define macro(a) (@{__typeof__(a) b = (a); b + 3; @})
180 template<typename T> T function(T a) @{ T b = a; return b + 3; @}
190 will have different places where temporaries are destroyed. For the
191 @code{macro} case, the temporary @code{X} will be destroyed just after
192 the initialization of @code{b}. In the @code{function} case that
193 temporary will be destroyed when the function returns.
195 These considerations mean that it is probably a bad idea to use
196 statement-expressions of this form in header files that are designed to
197 work with C++. (Note that some versions of the GNU C Library contained
198 header files using statement-expression that lead to precisely this
201 Jumping into a statement expression with @code{goto} or using a
202 @code{switch} statement outside the statement expression with a
203 @code{case} or @code{default} label inside the statement expression is
204 not permitted. Jumping into a statement expression with a computed
205 @code{goto} (@pxref{Labels as Values}) yields undefined behavior.
206 Jumping out of a statement expression is permitted, but if the
207 statement expression is part of a larger expression then it is
208 unspecified which other subexpressions of that expression have been
209 evaluated except where the language definition requires certain
210 subexpressions to be evaluated before or after the statement
211 expression. In any case, as with a function call the evaluation of a
212 statement expression is not interleaved with the evaluation of other
213 parts of the containing expression. For example,
216 foo (), ((@{ bar1 (); goto a; 0; @}) + bar2 ()), baz();
220 will call @code{foo} and @code{bar1} and will not call @code{baz} but
221 may or may not call @code{bar2}. If @code{bar2} is called, it will be
222 called after @code{foo} and before @code{bar1}
225 @section Locally Declared Labels
227 @cindex macros, local labels
229 GCC allows you to declare @dfn{local labels} in any nested block
230 scope. A local label is just like an ordinary label, but you can
231 only reference it (with a @code{goto} statement, or by taking its
232 address) within the block in which it was declared.
234 A local label declaration looks like this:
237 __label__ @var{label};
244 __label__ @var{label1}, @var{label2}, /* @r{@dots{}} */;
247 Local label declarations must come at the beginning of the block,
248 before any ordinary declarations or statements.
250 The label declaration defines the label @emph{name}, but does not define
251 the label itself. You must do this in the usual way, with
252 @code{@var{label}:}, within the statements of the statement expression.
254 The local label feature is useful for complex macros. If a macro
255 contains nested loops, a @code{goto} can be useful for breaking out of
256 them. However, an ordinary label whose scope is the whole function
257 cannot be used: if the macro can be expanded several times in one
258 function, the label will be multiply defined in that function. A
259 local label avoids this problem. For example:
262 #define SEARCH(value, array, target) \
265 typeof (target) _SEARCH_target = (target); \
266 typeof (*(array)) *_SEARCH_array = (array); \
269 for (i = 0; i < max; i++) \
270 for (j = 0; j < max; j++) \
271 if (_SEARCH_array[i][j] == _SEARCH_target) \
272 @{ (value) = i; goto found; @} \
278 This could also be written using a statement-expression:
281 #define SEARCH(array, target) \
284 typeof (target) _SEARCH_target = (target); \
285 typeof (*(array)) *_SEARCH_array = (array); \
288 for (i = 0; i < max; i++) \
289 for (j = 0; j < max; j++) \
290 if (_SEARCH_array[i][j] == _SEARCH_target) \
291 @{ value = i; goto found; @} \
298 Local label declarations also make the labels they declare visible to
299 nested functions, if there are any. @xref{Nested Functions}, for details.
301 @node Labels as Values
302 @section Labels as Values
303 @cindex labels as values
304 @cindex computed gotos
305 @cindex goto with computed label
306 @cindex address of a label
308 You can get the address of a label defined in the current function
309 (or a containing function) with the unary operator @samp{&&}. The
310 value has type @code{void *}. This value is a constant and can be used
311 wherever a constant of that type is valid. For example:
319 To use these values, you need to be able to jump to one. This is done
320 with the computed goto statement@footnote{The analogous feature in
321 Fortran is called an assigned goto, but that name seems inappropriate in
322 C, where one can do more than simply store label addresses in label
323 variables.}, @code{goto *@var{exp};}. For example,
330 Any expression of type @code{void *} is allowed.
332 One way of using these constants is in initializing a static array that
333 will serve as a jump table:
336 static void *array[] = @{ &&foo, &&bar, &&hack @};
339 Then you can select a label with indexing, like this:
346 Note that this does not check whether the subscript is in bounds---array
347 indexing in C never does that.
349 Such an array of label values serves a purpose much like that of the
350 @code{switch} statement. The @code{switch} statement is cleaner, so
351 use that rather than an array unless the problem does not fit a
352 @code{switch} statement very well.
354 Another use of label values is in an interpreter for threaded code.
355 The labels within the interpreter function can be stored in the
356 threaded code for super-fast dispatching.
358 You may not use this mechanism to jump to code in a different function.
359 If you do that, totally unpredictable things will happen. The best way to
360 avoid this is to store the label address only in automatic variables and
361 never pass it as an argument.
363 An alternate way to write the above example is
366 static const int array[] = @{ &&foo - &&foo, &&bar - &&foo,
368 goto *(&&foo + array[i]);
372 This is more friendly to code living in shared libraries, as it reduces
373 the number of dynamic relocations that are needed, and by consequence,
374 allows the data to be read-only.
376 The @code{&&foo} expressions for the same label might have different
377 values if the containing function is inlined or cloned. If a program
378 relies on them being always the same,
379 @code{__attribute__((__noinline__,__noclone__))} should be used to
380 prevent inlining and cloning. If @code{&&foo} is used in a static
381 variable initializer, inlining and cloning is forbidden.
383 @node Nested Functions
384 @section Nested Functions
385 @cindex nested functions
386 @cindex downward funargs
389 A @dfn{nested function} is a function defined inside another function.
390 (Nested functions are not supported for GNU C++.) The nested function's
391 name is local to the block where it is defined. For example, here we
392 define a nested function named @code{square}, and call it twice:
396 foo (double a, double b)
398 double square (double z) @{ return z * z; @}
400 return square (a) + square (b);
405 The nested function can access all the variables of the containing
406 function that are visible at the point of its definition. This is
407 called @dfn{lexical scoping}. For example, here we show a nested
408 function which uses an inherited variable named @code{offset}:
412 bar (int *array, int offset, int size)
414 int access (int *array, int index)
415 @{ return array[index + offset]; @}
418 for (i = 0; i < size; i++)
419 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
424 Nested function definitions are permitted within functions in the places
425 where variable definitions are allowed; that is, in any block, mixed
426 with the other declarations and statements in the block.
428 It is possible to call the nested function from outside the scope of its
429 name by storing its address or passing the address to another function:
432 hack (int *array, int size)
434 void store (int index, int value)
435 @{ array[index] = value; @}
437 intermediate (store, size);
441 Here, the function @code{intermediate} receives the address of
442 @code{store} as an argument. If @code{intermediate} calls @code{store},
443 the arguments given to @code{store} are used to store into @code{array}.
444 But this technique works only so long as the containing function
445 (@code{hack}, in this example) does not exit.
447 If you try to call the nested function through its address after the
448 containing function has exited, all hell will break loose. If you try
449 to call it after a containing scope level has exited, and if it refers
450 to some of the variables that are no longer in scope, you may be lucky,
451 but it's not wise to take the risk. If, however, the nested function
452 does not refer to anything that has gone out of scope, you should be
455 GCC implements taking the address of a nested function using a technique
456 called @dfn{trampolines}. This technique was described in
457 @cite{Lexical Closures for C++} (Thomas M. Breuel, USENIX
458 C++ Conference Proceedings, October 17-21, 1988).
460 A nested function can jump to a label inherited from a containing
461 function, provided the label was explicitly declared in the containing
462 function (@pxref{Local Labels}). Such a jump returns instantly to the
463 containing function, exiting the nested function which did the
464 @code{goto} and any intermediate functions as well. Here is an example:
468 bar (int *array, int offset, int size)
471 int access (int *array, int index)
475 return array[index + offset];
479 for (i = 0; i < size; i++)
480 /* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
484 /* @r{Control comes here from @code{access}
485 if it detects an error.} */
492 A nested function always has no linkage. Declaring one with
493 @code{extern} or @code{static} is erroneous. If you need to declare the nested function
494 before its definition, use @code{auto} (which is otherwise meaningless
495 for function declarations).
498 bar (int *array, int offset, int size)
501 auto int access (int *, int);
503 int access (int *array, int index)
507 return array[index + offset];
513 @node Constructing Calls
514 @section Constructing Function Calls
515 @cindex constructing calls
516 @cindex forwarding calls
518 Using the built-in functions described below, you can record
519 the arguments a function received, and call another function
520 with the same arguments, without knowing the number or types
523 You can also record the return value of that function call,
524 and later return that value, without knowing what data type
525 the function tried to return (as long as your caller expects
528 However, these built-in functions may interact badly with some
529 sophisticated features or other extensions of the language. It
530 is, therefore, not recommended to use them outside very simple
531 functions acting as mere forwarders for their arguments.
533 @deftypefn {Built-in Function} {void *} __builtin_apply_args ()
534 This built-in function returns a pointer to data
535 describing how to perform a call with the same arguments as were passed
536 to the current function.
538 The function saves the arg pointer register, structure value address,
539 and all registers that might be used to pass arguments to a function
540 into a block of memory allocated on the stack. Then it returns the
541 address of that block.
544 @deftypefn {Built-in Function} {void *} __builtin_apply (void (*@var{function})(), void *@var{arguments}, size_t @var{size})
545 This built-in function invokes @var{function}
546 with a copy of the parameters described by @var{arguments}
549 The value of @var{arguments} should be the value returned by
550 @code{__builtin_apply_args}. The argument @var{size} specifies the size
551 of the stack argument data, in bytes.
553 This function returns a pointer to data describing
554 how to return whatever value was returned by @var{function}. The data
555 is saved in a block of memory allocated on the stack.
557 It is not always simple to compute the proper value for @var{size}. The
558 value is used by @code{__builtin_apply} to compute the amount of data
559 that should be pushed on the stack and copied from the incoming argument
563 @deftypefn {Built-in Function} {void} __builtin_return (void *@var{result})
564 This built-in function returns the value described by @var{result} from
565 the containing function. You should specify, for @var{result}, a value
566 returned by @code{__builtin_apply}.
569 @deftypefn {Built-in Function} __builtin_va_arg_pack ()
570 This built-in function represents all anonymous arguments of an inline
571 function. It can be used only in inline functions which will be always
572 inlined, never compiled as a separate function, such as those using
573 @code{__attribute__ ((__always_inline__))} or
574 @code{__attribute__ ((__gnu_inline__))} extern inline functions.
575 It must be only passed as last argument to some other function
576 with variable arguments. This is useful for writing small wrapper
577 inlines for variable argument functions, when using preprocessor
578 macros is undesirable. For example:
580 extern int myprintf (FILE *f, const char *format, ...);
581 extern inline __attribute__ ((__gnu_inline__)) int
582 myprintf (FILE *f, const char *format, ...)
584 int r = fprintf (f, "myprintf: ");
587 int s = fprintf (f, format, __builtin_va_arg_pack ());
595 @deftypefn {Built-in Function} __builtin_va_arg_pack_len ()
596 This built-in function returns the number of anonymous arguments of
597 an inline function. It can be used only in inline functions which
598 will be always inlined, never compiled as a separate function, such
599 as those using @code{__attribute__ ((__always_inline__))} or
600 @code{__attribute__ ((__gnu_inline__))} extern inline functions.
601 For example following will do link or runtime checking of open
602 arguments for optimized code:
605 extern inline __attribute__((__gnu_inline__)) int
606 myopen (const char *path, int oflag, ...)
608 if (__builtin_va_arg_pack_len () > 1)
609 warn_open_too_many_arguments ();
611 if (__builtin_constant_p (oflag))
613 if ((oflag & O_CREAT) != 0 && __builtin_va_arg_pack_len () < 1)
615 warn_open_missing_mode ();
616 return __open_2 (path, oflag);
618 return open (path, oflag, __builtin_va_arg_pack ());
621 if (__builtin_va_arg_pack_len () < 1)
622 return __open_2 (path, oflag);
624 return open (path, oflag, __builtin_va_arg_pack ());
631 @section Referring to a Type with @code{typeof}
634 @cindex macros, types of arguments
636 Another way to refer to the type of an expression is with @code{typeof}.
637 The syntax of using of this keyword looks like @code{sizeof}, but the
638 construct acts semantically like a type name defined with @code{typedef}.
640 There are two ways of writing the argument to @code{typeof}: with an
641 expression or with a type. Here is an example with an expression:
648 This assumes that @code{x} is an array of pointers to functions;
649 the type described is that of the values of the functions.
651 Here is an example with a typename as the argument:
658 Here the type described is that of pointers to @code{int}.
660 If you are writing a header file that must work when included in ISO C
661 programs, write @code{__typeof__} instead of @code{typeof}.
662 @xref{Alternate Keywords}.
664 A @code{typeof}-construct can be used anywhere a typedef name could be
665 used. For example, you can use it in a declaration, in a cast, or inside
666 of @code{sizeof} or @code{typeof}.
668 The operand of @code{typeof} is evaluated for its side effects if and
669 only if it is an expression of variably modified type or the name of
672 @code{typeof} is often useful in conjunction with the
673 statements-within-expressions feature. Here is how the two together can
674 be used to define a safe ``maximum'' macro that operates on any
675 arithmetic type and evaluates each of its arguments exactly once:
679 (@{ typeof (a) _a = (a); \
680 typeof (b) _b = (b); \
681 _a > _b ? _a : _b; @})
684 @cindex underscores in variables in macros
685 @cindex @samp{_} in variables in macros
686 @cindex local variables in macros
687 @cindex variables, local, in macros
688 @cindex macros, local variables in
690 The reason for using names that start with underscores for the local
691 variables is to avoid conflicts with variable names that occur within the
692 expressions that are substituted for @code{a} and @code{b}. Eventually we
693 hope to design a new form of declaration syntax that allows you to declare
694 variables whose scopes start only after their initializers; this will be a
695 more reliable way to prevent such conflicts.
698 Some more examples of the use of @code{typeof}:
702 This declares @code{y} with the type of what @code{x} points to.
709 This declares @code{y} as an array of such values.
716 This declares @code{y} as an array of pointers to characters:
719 typeof (typeof (char *)[4]) y;
723 It is equivalent to the following traditional C declaration:
729 To see the meaning of the declaration using @code{typeof}, and why it
730 might be a useful way to write, rewrite it with these macros:
733 #define pointer(T) typeof(T *)
734 #define array(T, N) typeof(T [N])
738 Now the declaration can be rewritten this way:
741 array (pointer (char), 4) y;
745 Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
746 pointers to @code{char}.
749 @emph{Compatibility Note:} In addition to @code{typeof}, GCC 2 supported
750 a more limited extension which permitted one to write
753 typedef @var{T} = @var{expr};
757 with the effect of declaring @var{T} to have the type of the expression
758 @var{expr}. This extension does not work with GCC 3 (versions between
759 3.0 and 3.2 will crash; 3.2.1 and later give an error). Code which
760 relies on it should be rewritten to use @code{typeof}:
763 typedef typeof(@var{expr}) @var{T};
767 This will work with all versions of GCC@.
770 @section Conditionals with Omitted Operands
771 @cindex conditional expressions, extensions
772 @cindex omitted middle-operands
773 @cindex middle-operands, omitted
774 @cindex extensions, @code{?:}
775 @cindex @code{?:} extensions
777 The middle operand in a conditional expression may be omitted. Then
778 if the first operand is nonzero, its value is the value of the conditional
781 Therefore, the expression
788 has the value of @code{x} if that is nonzero; otherwise, the value of
791 This example is perfectly equivalent to
797 @cindex side effect in ?:
798 @cindex ?: side effect
800 In this simple case, the ability to omit the middle operand is not
801 especially useful. When it becomes useful is when the first operand does,
802 or may (if it is a macro argument), contain a side effect. Then repeating
803 the operand in the middle would perform the side effect twice. Omitting
804 the middle operand uses the value already computed without the undesirable
805 effects of recomputing it.
808 @section Double-Word Integers
809 @cindex @code{long long} data types
810 @cindex double-word arithmetic
811 @cindex multiprecision arithmetic
812 @cindex @code{LL} integer suffix
813 @cindex @code{ULL} integer suffix
815 ISO C99 supports data types for integers that are at least 64 bits wide,
816 and as an extension GCC supports them in C89 mode and in C++.
817 Simply write @code{long long int} for a signed integer, or
818 @code{unsigned long long int} for an unsigned integer. To make an
819 integer constant of type @code{long long int}, add the suffix @samp{LL}
820 to the integer. To make an integer constant of type @code{unsigned long
821 long int}, add the suffix @samp{ULL} to the integer.
823 You can use these types in arithmetic like any other integer types.
824 Addition, subtraction, and bitwise boolean operations on these types
825 are open-coded on all types of machines. Multiplication is open-coded
826 if the machine supports fullword-to-doubleword a widening multiply
827 instruction. Division and shifts are open-coded only on machines that
828 provide special support. The operations that are not open-coded use
829 special library routines that come with GCC@.
831 There may be pitfalls when you use @code{long long} types for function
832 arguments, unless you declare function prototypes. If a function
833 expects type @code{int} for its argument, and you pass a value of type
834 @code{long long int}, confusion will result because the caller and the
835 subroutine will disagree about the number of bytes for the argument.
836 Likewise, if the function expects @code{long long int} and you pass
837 @code{int}. The best way to avoid such problems is to use prototypes.
840 @section Complex Numbers
841 @cindex complex numbers
842 @cindex @code{_Complex} keyword
843 @cindex @code{__complex__} keyword
845 ISO C99 supports complex floating data types, and as an extension GCC
846 supports them in C89 mode and in C++, and supports complex integer data
847 types which are not part of ISO C99. You can declare complex types
848 using the keyword @code{_Complex}. As an extension, the older GNU
849 keyword @code{__complex__} is also supported.
851 For example, @samp{_Complex double x;} declares @code{x} as a
852 variable whose real part and imaginary part are both of type
853 @code{double}. @samp{_Complex short int y;} declares @code{y} to
854 have real and imaginary parts of type @code{short int}; this is not
855 likely to be useful, but it shows that the set of complex types is
858 To write a constant with a complex data type, use the suffix @samp{i} or
859 @samp{j} (either one; they are equivalent). For example, @code{2.5fi}
860 has type @code{_Complex float} and @code{3i} has type
861 @code{_Complex int}. Such a constant always has a pure imaginary
862 value, but you can form any complex value you like by adding one to a
863 real constant. This is a GNU extension; if you have an ISO C99
864 conforming C library (such as GNU libc), and want to construct complex
865 constants of floating type, you should include @code{<complex.h>} and
866 use the macros @code{I} or @code{_Complex_I} instead.
868 @cindex @code{__real__} keyword
869 @cindex @code{__imag__} keyword
870 To extract the real part of a complex-valued expression @var{exp}, write
871 @code{__real__ @var{exp}}. Likewise, use @code{__imag__} to
872 extract the imaginary part. This is a GNU extension; for values of
873 floating type, you should use the ISO C99 functions @code{crealf},
874 @code{creal}, @code{creall}, @code{cimagf}, @code{cimag} and
875 @code{cimagl}, declared in @code{<complex.h>} and also provided as
876 built-in functions by GCC@.
878 @cindex complex conjugation
879 The operator @samp{~} performs complex conjugation when used on a value
880 with a complex type. This is a GNU extension; for values of
881 floating type, you should use the ISO C99 functions @code{conjf},
882 @code{conj} and @code{conjl}, declared in @code{<complex.h>} and also
883 provided as built-in functions by GCC@.
885 GCC can allocate complex automatic variables in a noncontiguous
886 fashion; it's even possible for the real part to be in a register while
887 the imaginary part is on the stack (or vice-versa). Only the DWARF2
888 debug info format can represent this, so use of DWARF2 is recommended.
889 If you are using the stabs debug info format, GCC describes a noncontiguous
890 complex variable as if it were two separate variables of noncomplex type.
891 If the variable's actual name is @code{foo}, the two fictitious
892 variables are named @code{foo$real} and @code{foo$imag}. You can
893 examine and set these two fictitious variables with your debugger.
896 @section Additional Floating Types
897 @cindex additional floating types
898 @cindex @code{__float80} data type
899 @cindex @code{__float128} data type
900 @cindex @code{w} floating point suffix
901 @cindex @code{q} floating point suffix
902 @cindex @code{W} floating point suffix
903 @cindex @code{Q} floating point suffix
905 As an extension, the GNU C compiler supports additional floating
906 types, @code{__float80} and @code{__float128} to support 80bit
907 (@code{XFmode}) and 128 bit (@code{TFmode}) floating types.
908 Support for additional types includes the arithmetic operators:
909 add, subtract, multiply, divide; unary arithmetic operators;
910 relational operators; equality operators; and conversions to and from
911 integer and other floating types. Use a suffix @samp{w} or @samp{W}
912 in a literal constant of type @code{__float80} and @samp{q} or @samp{Q}
913 for @code{_float128}. You can declare complex types using the
914 corresponding internal complex type, @code{XCmode} for @code{__float80}
915 type and @code{TCmode} for @code{__float128} type:
918 typedef _Complex float __attribute__((mode(TC))) _Complex128;
919 typedef _Complex float __attribute__((mode(XC))) _Complex80;
922 Not all targets support additional floating point types. @code{__float80}
923 and @code{__float128} types are supported on i386, x86_64 and ia64 targets.
926 @section Half-Precision Floating Point
927 @cindex half-precision floating point
928 @cindex @code{__fp16} data type
930 On ARM targets, GCC supports half-precision (16-bit) floating point via
931 the @code{__fp16} type. You must enable this type explicitly
932 with the @option{-mfp16-format} command-line option in order to use it.
934 ARM supports two incompatible representations for half-precision
935 floating-point values. You must choose one of the representations and
936 use it consistently in your program.
938 Specifying @option{-mfp16-format=ieee} selects the IEEE 754-2008 format.
939 This format can represent normalized values in the range of @math{2^{-14}} to 65504.
940 There are 11 bits of significand precision, approximately 3
943 Specifying @option{-mfp16-format=alternative} selects the ARM
944 alternative format. This representation is similar to the IEEE
945 format, but does not support infinities or NaNs. Instead, the range
946 of exponents is extended, so that this format can represent normalized
947 values in the range of @math{2^{-14}} to 131008.
949 The @code{__fp16} type is a storage format only. For purposes
950 of arithmetic and other operations, @code{__fp16} values in C or C++
951 expressions are automatically promoted to @code{float}. In addition,
952 you cannot declare a function with a return value or parameters
953 of type @code{__fp16}.
955 Note that conversions from @code{double} to @code{__fp16}
956 involve an intermediate conversion to @code{float}. Because
957 of rounding, this can sometimes produce a different result than a
960 ARM provides hardware support for conversions between
961 @code{__fp16} and @code{float} values
962 as an extension to VFP and NEON (Advanced SIMD). GCC generates
963 code using these hardware instructions if you compile with
964 options to select an FPU that provides them;
965 for example, @option{-mfpu=neon-fp16 -mfloat-abi=softfp},
966 in addition to the @option{-mfp16-format} option to select
967 a half-precision format.
969 Language-level support for the @code{__fp16} data type is
970 independent of whether GCC generates code using hardware floating-point
971 instructions. In cases where hardware support is not specified, GCC
972 implements conversions between @code{__fp16} and @code{float} values
976 @section Decimal Floating Types
977 @cindex decimal floating types
978 @cindex @code{_Decimal32} data type
979 @cindex @code{_Decimal64} data type
980 @cindex @code{_Decimal128} data type
981 @cindex @code{df} integer suffix
982 @cindex @code{dd} integer suffix
983 @cindex @code{dl} integer suffix
984 @cindex @code{DF} integer suffix
985 @cindex @code{DD} integer suffix
986 @cindex @code{DL} integer suffix
988 As an extension, the GNU C compiler supports decimal floating types as
989 defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal
990 floating types in GCC will evolve as the draft technical report changes.
991 Calling conventions for any target might also change. Not all targets
992 support decimal floating types.
994 The decimal floating types are @code{_Decimal32}, @code{_Decimal64}, and
995 @code{_Decimal128}. They use a radix of ten, unlike the floating types
996 @code{float}, @code{double}, and @code{long double} whose radix is not
997 specified by the C standard but is usually two.
999 Support for decimal floating types includes the arithmetic operators
1000 add, subtract, multiply, divide; unary arithmetic operators;
1001 relational operators; equality operators; and conversions to and from
1002 integer and other floating types. Use a suffix @samp{df} or
1003 @samp{DF} in a literal constant of type @code{_Decimal32}, @samp{dd}
1004 or @samp{DD} for @code{_Decimal64}, and @samp{dl} or @samp{DL} for
1007 GCC support of decimal float as specified by the draft technical report
1012 When the value of a decimal floating type cannot be represented in the
1013 integer type to which it is being converted, the result is undefined
1014 rather than the result value specified by the draft technical report.
1017 GCC does not provide the C library functionality associated with
1018 @file{math.h}, @file{fenv.h}, @file{stdio.h}, @file{stdlib.h}, and
1019 @file{wchar.h}, which must come from a separate C library implementation.
1020 Because of this the GNU C compiler does not define macro
1021 @code{__STDC_DEC_FP__} to indicate that the implementation conforms to
1022 the technical report.
1025 Types @code{_Decimal32}, @code{_Decimal64}, and @code{_Decimal128}
1026 are supported by the DWARF2 debug information format.
1032 ISO C99 supports floating-point numbers written not only in the usual
1033 decimal notation, such as @code{1.55e1}, but also numbers such as
1034 @code{0x1.fp3} written in hexadecimal format. As a GNU extension, GCC
1035 supports this in C89 mode (except in some cases when strictly
1036 conforming) and in C++. In that format the
1037 @samp{0x} hex introducer and the @samp{p} or @samp{P} exponent field are
1038 mandatory. The exponent is a decimal number that indicates the power of
1039 2 by which the significant part will be multiplied. Thus @samp{0x1.f} is
1046 @samp{p3} multiplies it by 8, and the value of @code{0x1.fp3}
1047 is the same as @code{1.55e1}.
1049 Unlike for floating-point numbers in the decimal notation the exponent
1050 is always required in the hexadecimal notation. Otherwise the compiler
1051 would not be able to resolve the ambiguity of, e.g., @code{0x1.f}. This
1052 could mean @code{1.0f} or @code{1.9375} since @samp{f} is also the
1053 extension for floating-point constants of type @code{float}.
1056 @section Fixed-Point Types
1057 @cindex fixed-point types
1058 @cindex @code{_Fract} data type
1059 @cindex @code{_Accum} data type
1060 @cindex @code{_Sat} data type
1061 @cindex @code{hr} fixed-suffix
1062 @cindex @code{r} fixed-suffix
1063 @cindex @code{lr} fixed-suffix
1064 @cindex @code{llr} fixed-suffix
1065 @cindex @code{uhr} fixed-suffix
1066 @cindex @code{ur} fixed-suffix
1067 @cindex @code{ulr} fixed-suffix
1068 @cindex @code{ullr} fixed-suffix
1069 @cindex @code{hk} fixed-suffix
1070 @cindex @code{k} fixed-suffix
1071 @cindex @code{lk} fixed-suffix
1072 @cindex @code{llk} fixed-suffix
1073 @cindex @code{uhk} fixed-suffix
1074 @cindex @code{uk} fixed-suffix
1075 @cindex @code{ulk} fixed-suffix
1076 @cindex @code{ullk} fixed-suffix
1077 @cindex @code{HR} fixed-suffix
1078 @cindex @code{R} fixed-suffix
1079 @cindex @code{LR} fixed-suffix
1080 @cindex @code{LLR} fixed-suffix
1081 @cindex @code{UHR} fixed-suffix
1082 @cindex @code{UR} fixed-suffix
1083 @cindex @code{ULR} fixed-suffix
1084 @cindex @code{ULLR} fixed-suffix
1085 @cindex @code{HK} fixed-suffix
1086 @cindex @code{K} fixed-suffix
1087 @cindex @code{LK} fixed-suffix
1088 @cindex @code{LLK} fixed-suffix
1089 @cindex @code{UHK} fixed-suffix
1090 @cindex @code{UK} fixed-suffix
1091 @cindex @code{ULK} fixed-suffix
1092 @cindex @code{ULLK} fixed-suffix
1094 As an extension, the GNU C compiler supports fixed-point types as
1095 defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point
1096 types in GCC will evolve as the draft technical report changes.
1097 Calling conventions for any target might also change. Not all targets
1098 support fixed-point types.
1100 The fixed-point types are
1101 @code{short _Fract},
1104 @code{long long _Fract},
1105 @code{unsigned short _Fract},
1106 @code{unsigned _Fract},
1107 @code{unsigned long _Fract},
1108 @code{unsigned long long _Fract},
1109 @code{_Sat short _Fract},
1111 @code{_Sat long _Fract},
1112 @code{_Sat long long _Fract},
1113 @code{_Sat unsigned short _Fract},
1114 @code{_Sat unsigned _Fract},
1115 @code{_Sat unsigned long _Fract},
1116 @code{_Sat unsigned long long _Fract},
1117 @code{short _Accum},
1120 @code{long long _Accum},
1121 @code{unsigned short _Accum},
1122 @code{unsigned _Accum},
1123 @code{unsigned long _Accum},
1124 @code{unsigned long long _Accum},
1125 @code{_Sat short _Accum},
1127 @code{_Sat long _Accum},
1128 @code{_Sat long long _Accum},
1129 @code{_Sat unsigned short _Accum},
1130 @code{_Sat unsigned _Accum},
1131 @code{_Sat unsigned long _Accum},
1132 @code{_Sat unsigned long long _Accum}.
1134 Fixed-point data values contain fractional and optional integral parts.
1135 The format of fixed-point data varies and depends on the target machine.
1137 Support for fixed-point types includes:
1140 prefix and postfix increment and decrement operators (@code{++}, @code{--})
1142 unary arithmetic operators (@code{+}, @code{-}, @code{!})
1144 binary arithmetic operators (@code{+}, @code{-}, @code{*}, @code{/})
1146 binary shift operators (@code{<<}, @code{>>})
1148 relational operators (@code{<}, @code{<=}, @code{>=}, @code{>})
1150 equality operators (@code{==}, @code{!=})
1152 assignment operators (@code{+=}, @code{-=}, @code{*=}, @code{/=},
1153 @code{<<=}, @code{>>=})
1155 conversions to and from integer, floating-point, or fixed-point types
1158 Use a suffix in a fixed-point literal constant:
1160 @item @samp{hr} or @samp{HR} for @code{short _Fract} and
1161 @code{_Sat short _Fract}
1162 @item @samp{r} or @samp{R} for @code{_Fract} and @code{_Sat _Fract}
1163 @item @samp{lr} or @samp{LR} for @code{long _Fract} and
1164 @code{_Sat long _Fract}
1165 @item @samp{llr} or @samp{LLR} for @code{long long _Fract} and
1166 @code{_Sat long long _Fract}
1167 @item @samp{uhr} or @samp{UHR} for @code{unsigned short _Fract} and
1168 @code{_Sat unsigned short _Fract}
1169 @item @samp{ur} or @samp{UR} for @code{unsigned _Fract} and
1170 @code{_Sat unsigned _Fract}
1171 @item @samp{ulr} or @samp{ULR} for @code{unsigned long _Fract} and
1172 @code{_Sat unsigned long _Fract}
1173 @item @samp{ullr} or @samp{ULLR} for @code{unsigned long long _Fract}
1174 and @code{_Sat unsigned long long _Fract}
1175 @item @samp{hk} or @samp{HK} for @code{short _Accum} and
1176 @code{_Sat short _Accum}
1177 @item @samp{k} or @samp{K} for @code{_Accum} and @code{_Sat _Accum}
1178 @item @samp{lk} or @samp{LK} for @code{long _Accum} and
1179 @code{_Sat long _Accum}
1180 @item @samp{llk} or @samp{LLK} for @code{long long _Accum} and
1181 @code{_Sat long long _Accum}
1182 @item @samp{uhk} or @samp{UHK} for @code{unsigned short _Accum} and
1183 @code{_Sat unsigned short _Accum}
1184 @item @samp{uk} or @samp{UK} for @code{unsigned _Accum} and
1185 @code{_Sat unsigned _Accum}
1186 @item @samp{ulk} or @samp{ULK} for @code{unsigned long _Accum} and
1187 @code{_Sat unsigned long _Accum}
1188 @item @samp{ullk} or @samp{ULLK} for @code{unsigned long long _Accum}
1189 and @code{_Sat unsigned long long _Accum}
1192 GCC support of fixed-point types as specified by the draft technical report
1197 Pragmas to control overflow and rounding behaviors are not implemented.
1200 Fixed-point types are supported by the DWARF2 debug information format.
1202 @node Named Address Spaces
1203 @section Named address spaces
1204 @cindex named address spaces
1206 As an extension, the GNU C compiler supports named address spaces as
1207 defined in the N1275 draft of ISO/IEC DTR 18037. Support for named
1208 address spaces in GCC will evolve as the draft technical report changes.
1209 Calling conventions for any target might also change. At present, only
1210 the SPU target supports other address spaces. On the SPU target, for
1211 example, variables may be declared as belonging to another address space
1212 by qualifying the type with the @code{__ea} address space identifier:
1218 When the variable @code{i} is accessed, the compiler will generate
1219 special code to access this variable. It may use runtime library
1220 support, or generate special machine instructions to access that address
1223 The @code{__ea} identifier may be used exactly like any other C type
1224 qualifier (e.g., @code{const} or @code{volatile}). See the N1275
1225 document for more details.
1228 @section Arrays of Length Zero
1229 @cindex arrays of length zero
1230 @cindex zero-length arrays
1231 @cindex length-zero arrays
1232 @cindex flexible array members
1234 Zero-length arrays are allowed in GNU C@. They are very useful as the
1235 last element of a structure which is really a header for a variable-length
1244 struct line *thisline = (struct line *)
1245 malloc (sizeof (struct line) + this_length);
1246 thisline->length = this_length;
1249 In ISO C90, you would have to give @code{contents} a length of 1, which
1250 means either you waste space or complicate the argument to @code{malloc}.
1252 In ISO C99, you would use a @dfn{flexible array member}, which is
1253 slightly different in syntax and semantics:
1257 Flexible array members are written as @code{contents[]} without
1261 Flexible array members have incomplete type, and so the @code{sizeof}
1262 operator may not be applied. As a quirk of the original implementation
1263 of zero-length arrays, @code{sizeof} evaluates to zero.
1266 Flexible array members may only appear as the last member of a
1267 @code{struct} that is otherwise non-empty.
1270 A structure containing a flexible array member, or a union containing
1271 such a structure (possibly recursively), may not be a member of a
1272 structure or an element of an array. (However, these uses are
1273 permitted by GCC as extensions.)
1276 GCC versions before 3.0 allowed zero-length arrays to be statically
1277 initialized, as if they were flexible arrays. In addition to those
1278 cases that were useful, it also allowed initializations in situations
1279 that would corrupt later data. Non-empty initialization of zero-length
1280 arrays is now treated like any case where there are more initializer
1281 elements than the array holds, in that a suitable warning about "excess
1282 elements in array" is given, and the excess elements (all of them, in
1283 this case) are ignored.
1285 Instead GCC allows static initialization of flexible array members.
1286 This is equivalent to defining a new structure containing the original
1287 structure followed by an array of sufficient size to contain the data.
1288 I.e.@: in the following, @code{f1} is constructed as if it were declared
1294 @} f1 = @{ 1, @{ 2, 3, 4 @} @};
1297 struct f1 f1; int data[3];
1298 @} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @};
1302 The convenience of this extension is that @code{f1} has the desired
1303 type, eliminating the need to consistently refer to @code{f2.f1}.
1305 This has symmetry with normal static arrays, in that an array of
1306 unknown size is also written with @code{[]}.
1308 Of course, this extension only makes sense if the extra data comes at
1309 the end of a top-level object, as otherwise we would be overwriting
1310 data at subsequent offsets. To avoid undue complication and confusion
1311 with initialization of deeply nested arrays, we simply disallow any
1312 non-empty initialization except when the structure is the top-level
1313 object. For example:
1316 struct foo @{ int x; int y[]; @};
1317 struct bar @{ struct foo z; @};
1319 struct foo a = @{ 1, @{ 2, 3, 4 @} @}; // @r{Valid.}
1320 struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1321 struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.}
1322 struct foo d[1] = @{ @{ 1 @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
1325 @node Empty Structures
1326 @section Structures With No Members
1327 @cindex empty structures
1328 @cindex zero-size structures
1330 GCC permits a C structure to have no members:
1337 The structure will have size zero. In C++, empty structures are part
1338 of the language. G++ treats empty structures as if they had a single
1339 member of type @code{char}.
1341 @node Variable Length
1342 @section Arrays of Variable Length
1343 @cindex variable-length arrays
1344 @cindex arrays of variable length
1347 Variable-length automatic arrays are allowed in ISO C99, and as an
1348 extension GCC accepts them in C89 mode and in C++. (However, GCC's
1349 implementation of variable-length arrays does not yet conform in detail
1350 to the ISO C99 standard.) These arrays are
1351 declared like any other automatic arrays, but with a length that is not
1352 a constant expression. The storage is allocated at the point of
1353 declaration and deallocated when the brace-level is exited. For
1358 concat_fopen (char *s1, char *s2, char *mode)
1360 char str[strlen (s1) + strlen (s2) + 1];
1363 return fopen (str, mode);
1367 @cindex scope of a variable length array
1368 @cindex variable-length array scope
1369 @cindex deallocating variable length arrays
1370 Jumping or breaking out of the scope of the array name deallocates the
1371 storage. Jumping into the scope is not allowed; you get an error
1374 @cindex @code{alloca} vs variable-length arrays
1375 You can use the function @code{alloca} to get an effect much like
1376 variable-length arrays. The function @code{alloca} is available in
1377 many other C implementations (but not in all). On the other hand,
1378 variable-length arrays are more elegant.
1380 There are other differences between these two methods. Space allocated
1381 with @code{alloca} exists until the containing @emph{function} returns.
1382 The space for a variable-length array is deallocated as soon as the array
1383 name's scope ends. (If you use both variable-length arrays and
1384 @code{alloca} in the same function, deallocation of a variable-length array
1385 will also deallocate anything more recently allocated with @code{alloca}.)
1387 You can also use variable-length arrays as arguments to functions:
1391 tester (int len, char data[len][len])
1397 The length of an array is computed once when the storage is allocated
1398 and is remembered for the scope of the array in case you access it with
1401 If you want to pass the array first and the length afterward, you can
1402 use a forward declaration in the parameter list---another GNU extension.
1406 tester (int len; char data[len][len], int len)
1412 @cindex parameter forward declaration
1413 The @samp{int len} before the semicolon is a @dfn{parameter forward
1414 declaration}, and it serves the purpose of making the name @code{len}
1415 known when the declaration of @code{data} is parsed.
1417 You can write any number of such parameter forward declarations in the
1418 parameter list. They can be separated by commas or semicolons, but the
1419 last one must end with a semicolon, which is followed by the ``real''
1420 parameter declarations. Each forward declaration must match a ``real''
1421 declaration in parameter name and data type. ISO C99 does not support
1422 parameter forward declarations.
1424 @node Variadic Macros
1425 @section Macros with a Variable Number of Arguments.
1426 @cindex variable number of arguments
1427 @cindex macro with variable arguments
1428 @cindex rest argument (in macro)
1429 @cindex variadic macros
1431 In the ISO C standard of 1999, a macro can be declared to accept a
1432 variable number of arguments much as a function can. The syntax for
1433 defining the macro is similar to that of a function. Here is an
1437 #define debug(format, ...) fprintf (stderr, format, __VA_ARGS__)
1440 Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of
1441 such a macro, it represents the zero or more tokens until the closing
1442 parenthesis that ends the invocation, including any commas. This set of
1443 tokens replaces the identifier @code{__VA_ARGS__} in the macro body
1444 wherever it appears. See the CPP manual for more information.
1446 GCC has long supported variadic macros, and used a different syntax that
1447 allowed you to give a name to the variable arguments just like any other
1448 argument. Here is an example:
1451 #define debug(format, args...) fprintf (stderr, format, args)
1454 This is in all ways equivalent to the ISO C example above, but arguably
1455 more readable and descriptive.
1457 GNU CPP has two further variadic macro extensions, and permits them to
1458 be used with either of the above forms of macro definition.
1460 In standard C, you are not allowed to leave the variable argument out
1461 entirely; but you are allowed to pass an empty argument. For example,
1462 this invocation is invalid in ISO C, because there is no comma after
1469 GNU CPP permits you to completely omit the variable arguments in this
1470 way. In the above examples, the compiler would complain, though since
1471 the expansion of the macro still has the extra comma after the format
1474 To help solve this problem, CPP behaves specially for variable arguments
1475 used with the token paste operator, @samp{##}. If instead you write
1478 #define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
1481 and if the variable arguments are omitted or empty, the @samp{##}
1482 operator causes the preprocessor to remove the comma before it. If you
1483 do provide some variable arguments in your macro invocation, GNU CPP
1484 does not complain about the paste operation and instead places the
1485 variable arguments after the comma. Just like any other pasted macro
1486 argument, these arguments are not macro expanded.
1488 @node Escaped Newlines
1489 @section Slightly Looser Rules for Escaped Newlines
1490 @cindex escaped newlines
1491 @cindex newlines (escaped)
1493 Recently, the preprocessor has relaxed its treatment of escaped
1494 newlines. Previously, the newline had to immediately follow a
1495 backslash. The current implementation allows whitespace in the form
1496 of spaces, horizontal and vertical tabs, and form feeds between the
1497 backslash and the subsequent newline. The preprocessor issues a
1498 warning, but treats it as a valid escaped newline and combines the two
1499 lines to form a single logical line. This works within comments and
1500 tokens, as well as between tokens. Comments are @emph{not} treated as
1501 whitespace for the purposes of this relaxation, since they have not
1502 yet been replaced with spaces.
1505 @section Non-Lvalue Arrays May Have Subscripts
1506 @cindex subscripting
1507 @cindex arrays, non-lvalue
1509 @cindex subscripting and function values
1510 In ISO C99, arrays that are not lvalues still decay to pointers, and
1511 may be subscripted, although they may not be modified or used after
1512 the next sequence point and the unary @samp{&} operator may not be
1513 applied to them. As an extension, GCC allows such arrays to be
1514 subscripted in C89 mode, though otherwise they do not decay to
1515 pointers outside C99 mode. For example,
1516 this is valid in GNU C though not valid in C89:
1520 struct foo @{int a[4];@};
1526 return f().a[index];
1532 @section Arithmetic on @code{void}- and Function-Pointers
1533 @cindex void pointers, arithmetic
1534 @cindex void, size of pointer to
1535 @cindex function pointers, arithmetic
1536 @cindex function, size of pointer to
1538 In GNU C, addition and subtraction operations are supported on pointers to
1539 @code{void} and on pointers to functions. This is done by treating the
1540 size of a @code{void} or of a function as 1.
1542 A consequence of this is that @code{sizeof} is also allowed on @code{void}
1543 and on function types, and returns 1.
1545 @opindex Wpointer-arith
1546 The option @option{-Wpointer-arith} requests a warning if these extensions
1550 @section Non-Constant Initializers
1551 @cindex initializers, non-constant
1552 @cindex non-constant initializers
1554 As in standard C++ and ISO C99, the elements of an aggregate initializer for an
1555 automatic variable are not required to be constant expressions in GNU C@.
1556 Here is an example of an initializer with run-time varying elements:
1559 foo (float f, float g)
1561 float beat_freqs[2] = @{ f-g, f+g @};
1566 @node Compound Literals
1567 @section Compound Literals
1568 @cindex constructor expressions
1569 @cindex initializations in expressions
1570 @cindex structures, constructor expression
1571 @cindex expressions, constructor
1572 @cindex compound literals
1573 @c The GNU C name for what C99 calls compound literals was "constructor expressions".
1575 ISO C99 supports compound literals. A compound literal looks like
1576 a cast containing an initializer. Its value is an object of the
1577 type specified in the cast, containing the elements specified in
1578 the initializer; it is an lvalue. As an extension, GCC supports
1579 compound literals in C89 mode and in C++.
1581 Usually, the specified type is a structure. Assume that
1582 @code{struct foo} and @code{structure} are declared as shown:
1585 struct foo @{int a; char b[2];@} structure;
1589 Here is an example of constructing a @code{struct foo} with a compound literal:
1592 structure = ((struct foo) @{x + y, 'a', 0@});
1596 This is equivalent to writing the following:
1600 struct foo temp = @{x + y, 'a', 0@};
1605 You can also construct an array. If all the elements of the compound literal
1606 are (made up of) simple constant expressions, suitable for use in
1607 initializers of objects of static storage duration, then the compound
1608 literal can be coerced to a pointer to its first element and used in
1609 such an initializer, as shown here:
1612 char **foo = (char *[]) @{ "x", "y", "z" @};
1615 Compound literals for scalar types and union types are is
1616 also allowed, but then the compound literal is equivalent
1619 As a GNU extension, GCC allows initialization of objects with static storage
1620 duration by compound literals (which is not possible in ISO C99, because
1621 the initializer is not a constant).
1622 It is handled as if the object was initialized only with the bracket
1623 enclosed list if the types of the compound literal and the object match.
1624 The initializer list of the compound literal must be constant.
1625 If the object being initialized has array type of unknown size, the size is
1626 determined by compound literal size.
1629 static struct foo x = (struct foo) @{1, 'a', 'b'@};
1630 static int y[] = (int []) @{1, 2, 3@};
1631 static int z[] = (int [3]) @{1@};
1635 The above lines are equivalent to the following:
1637 static struct foo x = @{1, 'a', 'b'@};
1638 static int y[] = @{1, 2, 3@};
1639 static int z[] = @{1, 0, 0@};
1642 @node Designated Inits
1643 @section Designated Initializers
1644 @cindex initializers with labeled elements
1645 @cindex labeled elements in initializers
1646 @cindex case labels in initializers
1647 @cindex designated initializers
1649 Standard C89 requires the elements of an initializer to appear in a fixed
1650 order, the same as the order of the elements in the array or structure
1653 In ISO C99 you can give the elements in any order, specifying the array
1654 indices or structure field names they apply to, and GNU C allows this as
1655 an extension in C89 mode as well. This extension is not
1656 implemented in GNU C++.
1658 To specify an array index, write
1659 @samp{[@var{index}] =} before the element value. For example,
1662 int a[6] = @{ [4] = 29, [2] = 15 @};
1669 int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
1673 The index values must be constant expressions, even if the array being
1674 initialized is automatic.
1676 An alternative syntax for this which has been obsolete since GCC 2.5 but
1677 GCC still accepts is to write @samp{[@var{index}]} before the element
1678 value, with no @samp{=}.
1680 To initialize a range of elements to the same value, write
1681 @samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU
1682 extension. For example,
1685 int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
1689 If the value in it has side-effects, the side-effects will happen only once,
1690 not for each initialized field by the range initializer.
1693 Note that the length of the array is the highest value specified
1696 In a structure initializer, specify the name of a field to initialize
1697 with @samp{.@var{fieldname} =} before the element value. For example,
1698 given the following structure,
1701 struct point @{ int x, y; @};
1705 the following initialization
1708 struct point p = @{ .y = yvalue, .x = xvalue @};
1715 struct point p = @{ xvalue, yvalue @};
1718 Another syntax which has the same meaning, obsolete since GCC 2.5, is
1719 @samp{@var{fieldname}:}, as shown here:
1722 struct point p = @{ y: yvalue, x: xvalue @};
1726 The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
1727 @dfn{designator}. You can also use a designator (or the obsolete colon
1728 syntax) when initializing a union, to specify which element of the union
1729 should be used. For example,
1732 union foo @{ int i; double d; @};
1734 union foo f = @{ .d = 4 @};
1738 will convert 4 to a @code{double} to store it in the union using
1739 the second element. By contrast, casting 4 to type @code{union foo}
1740 would store it into the union as the integer @code{i}, since it is
1741 an integer. (@xref{Cast to Union}.)
1743 You can combine this technique of naming elements with ordinary C
1744 initialization of successive elements. Each initializer element that
1745 does not have a designator applies to the next consecutive element of the
1746 array or structure. For example,
1749 int a[6] = @{ [1] = v1, v2, [4] = v4 @};
1756 int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
1759 Labeling the elements of an array initializer is especially useful
1760 when the indices are characters or belong to an @code{enum} type.
1765 = @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1,
1766 ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @};
1769 @cindex designator lists
1770 You can also write a series of @samp{.@var{fieldname}} and
1771 @samp{[@var{index}]} designators before an @samp{=} to specify a
1772 nested subobject to initialize; the list is taken relative to the
1773 subobject corresponding to the closest surrounding brace pair. For
1774 example, with the @samp{struct point} declaration above:
1777 struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @};
1781 If the same field is initialized multiple times, it will have value from
1782 the last initialization. If any such overridden initialization has
1783 side-effect, it is unspecified whether the side-effect happens or not.
1784 Currently, GCC will discard them and issue a warning.
1787 @section Case Ranges
1789 @cindex ranges in case statements
1791 You can specify a range of consecutive values in a single @code{case} label,
1795 case @var{low} ... @var{high}:
1799 This has the same effect as the proper number of individual @code{case}
1800 labels, one for each integer value from @var{low} to @var{high}, inclusive.
1802 This feature is especially useful for ranges of ASCII character codes:
1808 @strong{Be careful:} Write spaces around the @code{...}, for otherwise
1809 it may be parsed wrong when you use it with integer values. For example,
1824 @section Cast to a Union Type
1825 @cindex cast to a union
1826 @cindex union, casting to a
1828 A cast to union type is similar to other casts, except that the type
1829 specified is a union type. You can specify the type either with
1830 @code{union @var{tag}} or with a typedef name. A cast to union is actually
1831 a constructor though, not a cast, and hence does not yield an lvalue like
1832 normal casts. (@xref{Compound Literals}.)
1834 The types that may be cast to the union type are those of the members
1835 of the union. Thus, given the following union and variables:
1838 union foo @{ int i; double d; @};
1844 both @code{x} and @code{y} can be cast to type @code{union foo}.
1846 Using the cast as the right-hand side of an assignment to a variable of
1847 union type is equivalent to storing in a member of the union:
1852 u = (union foo) x @equiv{} u.i = x
1853 u = (union foo) y @equiv{} u.d = y
1856 You can also use the union cast as a function argument:
1859 void hack (union foo);
1861 hack ((union foo) x);
1864 @node Mixed Declarations
1865 @section Mixed Declarations and Code
1866 @cindex mixed declarations and code
1867 @cindex declarations, mixed with code
1868 @cindex code, mixed with declarations
1870 ISO C99 and ISO C++ allow declarations and code to be freely mixed
1871 within compound statements. As an extension, GCC also allows this in
1872 C89 mode. For example, you could do:
1881 Each identifier is visible from where it is declared until the end of
1882 the enclosing block.
1884 @node Function Attributes
1885 @section Declaring Attributes of Functions
1886 @cindex function attributes
1887 @cindex declaring attributes of functions
1888 @cindex functions that never return
1889 @cindex functions that return more than once
1890 @cindex functions that have no side effects
1891 @cindex functions in arbitrary sections
1892 @cindex functions that behave like malloc
1893 @cindex @code{volatile} applied to function
1894 @cindex @code{const} applied to function
1895 @cindex functions with @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style arguments
1896 @cindex functions with non-null pointer arguments
1897 @cindex functions that are passed arguments in registers on the 386
1898 @cindex functions that pop the argument stack on the 386
1899 @cindex functions that do not pop the argument stack on the 386
1900 @cindex functions that have different compilation options on the 386
1901 @cindex functions that have different optimization options
1903 In GNU C, you declare certain things about functions called in your program
1904 which help the compiler optimize function calls and check your code more
1907 The keyword @code{__attribute__} allows you to specify special
1908 attributes when making a declaration. This keyword is followed by an
1909 attribute specification inside double parentheses. The following
1910 attributes are currently defined for functions on all targets:
1911 @code{aligned}, @code{alloc_size}, @code{noreturn},
1912 @code{returns_twice}, @code{noinline}, @code{noclone},
1913 @code{always_inline}, @code{flatten}, @code{pure}, @code{const},
1914 @code{nothrow}, @code{sentinel}, @code{format}, @code{format_arg},
1915 @code{no_instrument_function}, @code{section}, @code{constructor},
1916 @code{destructor}, @code{used}, @code{unused}, @code{deprecated},
1917 @code{weak}, @code{malloc}, @code{alias}, @code{warn_unused_result},
1918 @code{nonnull}, @code{gnu_inline}, @code{externally_visible},
1919 @code{hot}, @code{cold}, @code{artificial}, @code{error} and
1920 @code{warning}. Several other attributes are defined for functions on
1921 particular target systems. Other attributes, including @code{section}
1922 are supported for variables declarations (@pxref{Variable Attributes})
1923 and for types (@pxref{Type Attributes}).
1925 GCC plugins may provide their own attributes.
1927 You may also specify attributes with @samp{__} preceding and following
1928 each keyword. This allows you to use them in header files without
1929 being concerned about a possible macro of the same name. For example,
1930 you may use @code{__noreturn__} instead of @code{noreturn}.
1932 @xref{Attribute Syntax}, for details of the exact syntax for using
1936 @c Keep this table alphabetized by attribute name. Treat _ as space.
1938 @item alias ("@var{target}")
1939 @cindex @code{alias} attribute
1940 The @code{alias} attribute causes the declaration to be emitted as an
1941 alias for another symbol, which must be specified. For instance,
1944 void __f () @{ /* @r{Do something.} */; @}
1945 void f () __attribute__ ((weak, alias ("__f")));
1948 defines @samp{f} to be a weak alias for @samp{__f}. In C++, the
1949 mangled name for the target must be used. It is an error if @samp{__f}
1950 is not defined in the same translation unit.
1952 Not all target machines support this attribute.
1954 @item aligned (@var{alignment})
1955 @cindex @code{aligned} attribute
1956 This attribute specifies a minimum alignment for the function,
1959 You cannot use this attribute to decrease the alignment of a function,
1960 only to increase it. However, when you explicitly specify a function
1961 alignment this will override the effect of the
1962 @option{-falign-functions} (@pxref{Optimize Options}) option for this
1965 Note that the effectiveness of @code{aligned} attributes may be
1966 limited by inherent limitations in your linker. On many systems, the
1967 linker is only able to arrange for functions to be aligned up to a
1968 certain maximum alignment. (For some linkers, the maximum supported
1969 alignment may be very very small.) See your linker documentation for
1970 further information.
1972 The @code{aligned} attribute can also be used for variables and fields
1973 (@pxref{Variable Attributes}.)
1976 @cindex @code{alloc_size} attribute
1977 The @code{alloc_size} attribute is used to tell the compiler that the
1978 function return value points to memory, where the size is given by
1979 one or two of the functions parameters. GCC uses this
1980 information to improve the correctness of @code{__builtin_object_size}.
1982 The function parameter(s) denoting the allocated size are specified by
1983 one or two integer arguments supplied to the attribute. The allocated size
1984 is either the value of the single function argument specified or the product
1985 of the two function arguments specified. Argument numbering starts at
1991 void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2)))
1992 void my_realloc(void*, size_t) __attribute__((alloc_size(2)))
1995 declares that my_calloc will return memory of the size given by
1996 the product of parameter 1 and 2 and that my_realloc will return memory
1997 of the size given by parameter 2.
2000 @cindex @code{always_inline} function attribute
2001 Generally, functions are not inlined unless optimization is specified.
2002 For functions declared inline, this attribute inlines the function even
2003 if no optimization level was specified.
2006 @cindex @code{gnu_inline} function attribute
2007 This attribute should be used with a function which is also declared
2008 with the @code{inline} keyword. It directs GCC to treat the function
2009 as if it were defined in gnu89 mode even when compiling in C99 or
2012 If the function is declared @code{extern}, then this definition of the
2013 function is used only for inlining. In no case is the function
2014 compiled as a standalone function, not even if you take its address
2015 explicitly. Such an address becomes an external reference, as if you
2016 had only declared the function, and had not defined it. This has
2017 almost the effect of a macro. The way to use this is to put a
2018 function definition in a header file with this attribute, and put
2019 another copy of the function, without @code{extern}, in a library
2020 file. The definition in the header file will cause most calls to the
2021 function to be inlined. If any uses of the function remain, they will
2022 refer to the single copy in the library. Note that the two
2023 definitions of the functions need not be precisely the same, although
2024 if they do not have the same effect your program may behave oddly.
2026 In C, if the function is neither @code{extern} nor @code{static}, then
2027 the function is compiled as a standalone function, as well as being
2028 inlined where possible.
2030 This is how GCC traditionally handled functions declared
2031 @code{inline}. Since ISO C99 specifies a different semantics for
2032 @code{inline}, this function attribute is provided as a transition
2033 measure and as a useful feature in its own right. This attribute is
2034 available in GCC 4.1.3 and later. It is available if either of the
2035 preprocessor macros @code{__GNUC_GNU_INLINE__} or
2036 @code{__GNUC_STDC_INLINE__} are defined. @xref{Inline,,An Inline
2037 Function is As Fast As a Macro}.
2039 In C++, this attribute does not depend on @code{extern} in any way,
2040 but it still requires the @code{inline} keyword to enable its special
2044 @cindex @code{artificial} function attribute
2045 This attribute is useful for small inline wrappers which if possible
2046 should appear during debugging as a unit, depending on the debug
2047 info format it will either mean marking the function as artificial
2048 or using the caller location for all instructions within the inlined
2052 @cindex interrupt handler functions
2053 When added to an interrupt handler with the M32C port, causes the
2054 prologue and epilogue to use bank switching to preserve the registers
2055 rather than saving them on the stack.
2058 @cindex @code{flatten} function attribute
2059 Generally, inlining into a function is limited. For a function marked with
2060 this attribute, every call inside this function will be inlined, if possible.
2061 Whether the function itself is considered for inlining depends on its size and
2062 the current inlining parameters.
2064 @item error ("@var{message}")
2065 @cindex @code{error} function attribute
2066 If this attribute is used on a function declaration and a call to such a function
2067 is not eliminated through dead code elimination or other optimizations, an error
2068 which will include @var{message} will be diagnosed. This is useful
2069 for compile time checking, especially together with @code{__builtin_constant_p}
2070 and inline functions where checking the inline function arguments is not
2071 possible through @code{extern char [(condition) ? 1 : -1];} tricks.
2072 While it is possible to leave the function undefined and thus invoke
2073 a link failure, when using this attribute the problem will be diagnosed
2074 earlier and with exact location of the call even in presence of inline
2075 functions or when not emitting debugging information.
2077 @item warning ("@var{message}")
2078 @cindex @code{warning} function attribute
2079 If this attribute is used on a function declaration and a call to such a function
2080 is not eliminated through dead code elimination or other optimizations, a warning
2081 which will include @var{message} will be diagnosed. This is useful
2082 for compile time checking, especially together with @code{__builtin_constant_p}
2083 and inline functions. While it is possible to define the function with
2084 a message in @code{.gnu.warning*} section, when using this attribute the problem
2085 will be diagnosed earlier and with exact location of the call even in presence
2086 of inline functions or when not emitting debugging information.
2089 @cindex functions that do pop the argument stack on the 386
2091 On the Intel 386, the @code{cdecl} attribute causes the compiler to
2092 assume that the calling function will pop off the stack space used to
2093 pass arguments. This is
2094 useful to override the effects of the @option{-mrtd} switch.
2097 @cindex @code{const} function attribute
2098 Many functions do not examine any values except their arguments, and
2099 have no effects except the return value. Basically this is just slightly
2100 more strict class than the @code{pure} attribute below, since function is not
2101 allowed to read global memory.
2103 @cindex pointer arguments
2104 Note that a function that has pointer arguments and examines the data
2105 pointed to must @emph{not} be declared @code{const}. Likewise, a
2106 function that calls a non-@code{const} function usually must not be
2107 @code{const}. It does not make sense for a @code{const} function to
2110 The attribute @code{const} is not implemented in GCC versions earlier
2111 than 2.5. An alternative way to declare that a function has no side
2112 effects, which works in the current version and in some older versions,
2116 typedef int intfn ();
2118 extern const intfn square;
2121 This approach does not work in GNU C++ from 2.6.0 on, since the language
2122 specifies that the @samp{const} must be attached to the return value.
2126 @itemx constructor (@var{priority})
2127 @itemx destructor (@var{priority})
2128 @cindex @code{constructor} function attribute
2129 @cindex @code{destructor} function attribute
2130 The @code{constructor} attribute causes the function to be called
2131 automatically before execution enters @code{main ()}. Similarly, the
2132 @code{destructor} attribute causes the function to be called
2133 automatically after @code{main ()} has completed or @code{exit ()} has
2134 been called. Functions with these attributes are useful for
2135 initializing data that will be used implicitly during the execution of
2138 You may provide an optional integer priority to control the order in
2139 which constructor and destructor functions are run. A constructor
2140 with a smaller priority number runs before a constructor with a larger
2141 priority number; the opposite relationship holds for destructors. So,
2142 if you have a constructor that allocates a resource and a destructor
2143 that deallocates the same resource, both functions typically have the
2144 same priority. The priorities for constructor and destructor
2145 functions are the same as those specified for namespace-scope C++
2146 objects (@pxref{C++ Attributes}).
2148 These attributes are not currently implemented for Objective-C@.
2151 @itemx deprecated (@var{msg})
2152 @cindex @code{deprecated} attribute.
2153 The @code{deprecated} attribute results in a warning if the function
2154 is used anywhere in the source file. This is useful when identifying
2155 functions that are expected to be removed in a future version of a
2156 program. The warning also includes the location of the declaration
2157 of the deprecated function, to enable users to easily find further
2158 information about why the function is deprecated, or what they should
2159 do instead. Note that the warnings only occurs for uses:
2162 int old_fn () __attribute__ ((deprecated));
2164 int (*fn_ptr)() = old_fn;
2167 results in a warning on line 3 but not line 2. The optional msg
2168 argument, which must be a string, will be printed in the warning if
2171 The @code{deprecated} attribute can also be used for variables and
2172 types (@pxref{Variable Attributes}, @pxref{Type Attributes}.)
2175 @cindex @code{disinterrupt} attribute
2176 On MeP targets, this attribute causes the compiler to emit
2177 instructions to disable interrupts for the duration of the given
2181 @cindex @code{__declspec(dllexport)}
2182 On Microsoft Windows targets and Symbian OS targets the
2183 @code{dllexport} attribute causes the compiler to provide a global
2184 pointer to a pointer in a DLL, so that it can be referenced with the
2185 @code{dllimport} attribute. On Microsoft Windows targets, the pointer
2186 name is formed by combining @code{_imp__} and the function or variable
2189 You can use @code{__declspec(dllexport)} as a synonym for
2190 @code{__attribute__ ((dllexport))} for compatibility with other
2193 On systems that support the @code{visibility} attribute, this
2194 attribute also implies ``default'' visibility. It is an error to
2195 explicitly specify any other visibility.
2197 Currently, the @code{dllexport} attribute is ignored for inlined
2198 functions, unless the @option{-fkeep-inline-functions} flag has been
2199 used. The attribute is also ignored for undefined symbols.
2201 When applied to C++ classes, the attribute marks defined non-inlined
2202 member functions and static data members as exports. Static consts
2203 initialized in-class are not marked unless they are also defined
2206 For Microsoft Windows targets there are alternative methods for
2207 including the symbol in the DLL's export table such as using a
2208 @file{.def} file with an @code{EXPORTS} section or, with GNU ld, using
2209 the @option{--export-all} linker flag.
2212 @cindex @code{__declspec(dllimport)}
2213 On Microsoft Windows and Symbian OS targets, the @code{dllimport}
2214 attribute causes the compiler to reference a function or variable via
2215 a global pointer to a pointer that is set up by the DLL exporting the
2216 symbol. The attribute implies @code{extern}. On Microsoft Windows
2217 targets, the pointer name is formed by combining @code{_imp__} and the
2218 function or variable name.
2220 You can use @code{__declspec(dllimport)} as a synonym for
2221 @code{__attribute__ ((dllimport))} for compatibility with other
2224 On systems that support the @code{visibility} attribute, this
2225 attribute also implies ``default'' visibility. It is an error to
2226 explicitly specify any other visibility.
2228 Currently, the attribute is ignored for inlined functions. If the
2229 attribute is applied to a symbol @emph{definition}, an error is reported.
2230 If a symbol previously declared @code{dllimport} is later defined, the
2231 attribute is ignored in subsequent references, and a warning is emitted.
2232 The attribute is also overridden by a subsequent declaration as
2235 When applied to C++ classes, the attribute marks non-inlined
2236 member functions and static data members as imports. However, the
2237 attribute is ignored for virtual methods to allow creation of vtables
2240 On the SH Symbian OS target the @code{dllimport} attribute also has
2241 another affect---it can cause the vtable and run-time type information
2242 for a class to be exported. This happens when the class has a
2243 dllimport'ed constructor or a non-inline, non-pure virtual function
2244 and, for either of those two conditions, the class also has an inline
2245 constructor or destructor and has a key function that is defined in
2246 the current translation unit.
2248 For Microsoft Windows based targets the use of the @code{dllimport}
2249 attribute on functions is not necessary, but provides a small
2250 performance benefit by eliminating a thunk in the DLL@. The use of the
2251 @code{dllimport} attribute on imported variables was required on older
2252 versions of the GNU linker, but can now be avoided by passing the
2253 @option{--enable-auto-import} switch to the GNU linker. As with
2254 functions, using the attribute for a variable eliminates a thunk in
2257 One drawback to using this attribute is that a pointer to a
2258 @emph{variable} marked as @code{dllimport} cannot be used as a constant
2259 address. However, a pointer to a @emph{function} with the
2260 @code{dllimport} attribute can be used as a constant initializer; in
2261 this case, the address of a stub function in the import lib is
2262 referenced. On Microsoft Windows targets, the attribute can be disabled
2263 for functions by setting the @option{-mnop-fun-dllimport} flag.
2266 @cindex eight bit data on the H8/300, H8/300H, and H8S
2267 Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
2268 variable should be placed into the eight bit data section.
2269 The compiler will generate more efficient code for certain operations
2270 on data in the eight bit data area. Note the eight bit data area is limited to
2273 You must use GAS and GLD from GNU binutils version 2.7 or later for
2274 this attribute to work correctly.
2276 @item exception_handler
2277 @cindex exception handler functions on the Blackfin processor
2278 Use this attribute on the Blackfin to indicate that the specified function
2279 is an exception handler. The compiler will generate function entry and
2280 exit sequences suitable for use in an exception handler when this
2281 attribute is present.
2283 @item externally_visible
2284 @cindex @code{externally_visible} attribute.
2285 This attribute, attached to a global variable or function, nullifies
2286 the effect of the @option{-fwhole-program} command-line option, so the
2287 object remains visible outside the current compilation unit.
2290 @cindex functions which handle memory bank switching
2291 On 68HC11 and 68HC12 the @code{far} attribute causes the compiler to
2292 use a calling convention that takes care of switching memory banks when
2293 entering and leaving a function. This calling convention is also the
2294 default when using the @option{-mlong-calls} option.
2296 On 68HC12 the compiler will use the @code{call} and @code{rtc} instructions
2297 to call and return from a function.
2299 On 68HC11 the compiler will generate a sequence of instructions
2300 to invoke a board-specific routine to switch the memory bank and call the
2301 real function. The board-specific routine simulates a @code{call}.
2302 At the end of a function, it will jump to a board-specific routine
2303 instead of using @code{rts}. The board-specific return routine simulates
2306 On MeP targets this causes the compiler to use a calling convention
2307 which assumes the called function is too far away for the built-in
2310 @item fast_interrupt
2311 @cindex interrupt handler functions
2312 Use this attribute on the M32C and RX ports to indicate that the specified
2313 function is a fast interrupt handler. This is just like the
2314 @code{interrupt} attribute, except that @code{freit} is used to return
2315 instead of @code{reit}.
2318 @cindex functions that pop the argument stack on the 386
2319 On the Intel 386, the @code{fastcall} attribute causes the compiler to
2320 pass the first argument (if of integral type) in the register ECX and
2321 the second argument (if of integral type) in the register EDX@. Subsequent
2322 and other typed arguments are passed on the stack. The called function will
2323 pop the arguments off the stack. If the number of arguments is variable all
2324 arguments are pushed on the stack.
2326 @item format (@var{archetype}, @var{string-index}, @var{first-to-check})
2327 @cindex @code{format} function attribute
2329 The @code{format} attribute specifies that a function takes @code{printf},
2330 @code{scanf}, @code{strftime} or @code{strfmon} style arguments which
2331 should be type-checked against a format string. For example, the
2336 my_printf (void *my_object, const char *my_format, ...)
2337 __attribute__ ((format (printf, 2, 3)));
2341 causes the compiler to check the arguments in calls to @code{my_printf}
2342 for consistency with the @code{printf} style format string argument
2345 The parameter @var{archetype} determines how the format string is
2346 interpreted, and should be @code{printf}, @code{scanf}, @code{strftime},
2347 @code{gnu_printf}, @code{gnu_scanf}, @code{gnu_strftime} or
2348 @code{strfmon}. (You can also use @code{__printf__},
2349 @code{__scanf__}, @code{__strftime__} or @code{__strfmon__}.) On
2350 MinGW targets, @code{ms_printf}, @code{ms_scanf}, and
2351 @code{ms_strftime} are also present.
2352 @var{archtype} values such as @code{printf} refer to the formats accepted
2353 by the system's C run-time library, while @code{gnu_} values always refer
2354 to the formats accepted by the GNU C Library. On Microsoft Windows
2355 targets, @code{ms_} values refer to the formats accepted by the
2356 @file{msvcrt.dll} library.
2357 The parameter @var{string-index}
2358 specifies which argument is the format string argument (starting
2359 from 1), while @var{first-to-check} is the number of the first
2360 argument to check against the format string. For functions
2361 where the arguments are not available to be checked (such as
2362 @code{vprintf}), specify the third parameter as zero. In this case the
2363 compiler only checks the format string for consistency. For
2364 @code{strftime} formats, the third parameter is required to be zero.
2365 Since non-static C++ methods have an implicit @code{this} argument, the
2366 arguments of such methods should be counted from two, not one, when
2367 giving values for @var{string-index} and @var{first-to-check}.
2369 In the example above, the format string (@code{my_format}) is the second
2370 argument of the function @code{my_print}, and the arguments to check
2371 start with the third argument, so the correct parameters for the format
2372 attribute are 2 and 3.
2374 @opindex ffreestanding
2375 @opindex fno-builtin
2376 The @code{format} attribute allows you to identify your own functions
2377 which take format strings as arguments, so that GCC can check the
2378 calls to these functions for errors. The compiler always (unless
2379 @option{-ffreestanding} or @option{-fno-builtin} is used) checks formats
2380 for the standard library functions @code{printf}, @code{fprintf},
2381 @code{sprintf}, @code{scanf}, @code{fscanf}, @code{sscanf}, @code{strftime},
2382 @code{vprintf}, @code{vfprintf} and @code{vsprintf} whenever such
2383 warnings are requested (using @option{-Wformat}), so there is no need to
2384 modify the header file @file{stdio.h}. In C99 mode, the functions
2385 @code{snprintf}, @code{vsnprintf}, @code{vscanf}, @code{vfscanf} and
2386 @code{vsscanf} are also checked. Except in strictly conforming C
2387 standard modes, the X/Open function @code{strfmon} is also checked as
2388 are @code{printf_unlocked} and @code{fprintf_unlocked}.
2389 @xref{C Dialect Options,,Options Controlling C Dialect}.
2391 The target may provide additional types of format checks.
2392 @xref{Target Format Checks,,Format Checks Specific to Particular
2395 @item format_arg (@var{string-index})
2396 @cindex @code{format_arg} function attribute
2397 @opindex Wformat-nonliteral
2398 The @code{format_arg} attribute specifies that a function takes a format
2399 string for a @code{printf}, @code{scanf}, @code{strftime} or
2400 @code{strfmon} style function and modifies it (for example, to translate
2401 it into another language), so the result can be passed to a
2402 @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon} style
2403 function (with the remaining arguments to the format function the same
2404 as they would have been for the unmodified string). For example, the
2409 my_dgettext (char *my_domain, const char *my_format)
2410 __attribute__ ((format_arg (2)));
2414 causes the compiler to check the arguments in calls to a @code{printf},
2415 @code{scanf}, @code{strftime} or @code{strfmon} type function, whose
2416 format string argument is a call to the @code{my_dgettext} function, for
2417 consistency with the format string argument @code{my_format}. If the
2418 @code{format_arg} attribute had not been specified, all the compiler
2419 could tell in such calls to format functions would be that the format
2420 string argument is not constant; this would generate a warning when
2421 @option{-Wformat-nonliteral} is used, but the calls could not be checked
2422 without the attribute.
2424 The parameter @var{string-index} specifies which argument is the format
2425 string argument (starting from one). Since non-static C++ methods have
2426 an implicit @code{this} argument, the arguments of such methods should
2427 be counted from two.
2429 The @code{format-arg} attribute allows you to identify your own
2430 functions which modify format strings, so that GCC can check the
2431 calls to @code{printf}, @code{scanf}, @code{strftime} or @code{strfmon}
2432 type function whose operands are a call to one of your own function.
2433 The compiler always treats @code{gettext}, @code{dgettext}, and
2434 @code{dcgettext} in this manner except when strict ISO C support is
2435 requested by @option{-ansi} or an appropriate @option{-std} option, or
2436 @option{-ffreestanding} or @option{-fno-builtin}
2437 is used. @xref{C Dialect Options,,Options
2438 Controlling C Dialect}.
2440 @item function_vector
2441 @cindex calling functions through the function vector on H8/300, M16C, M32C and SH2A processors
2442 Use this attribute on the H8/300, H8/300H, and H8S to indicate that the specified
2443 function should be called through the function vector. Calling a
2444 function through the function vector will reduce code size, however;
2445 the function vector has a limited size (maximum 128 entries on the H8/300
2446 and 64 entries on the H8/300H and H8S) and shares space with the interrupt vector.
2448 In SH2A target, this attribute declares a function to be called using the
2449 TBR relative addressing mode. The argument to this attribute is the entry
2450 number of the same function in a vector table containing all the TBR
2451 relative addressable functions. For the successful jump, register TBR
2452 should contain the start address of this TBR relative vector table.
2453 In the startup routine of the user application, user needs to care of this
2454 TBR register initialization. The TBR relative vector table can have at
2455 max 256 function entries. The jumps to these functions will be generated
2456 using a SH2A specific, non delayed branch instruction JSR/N @@(disp8,TBR).
2457 You must use GAS and GLD from GNU binutils version 2.7 or later for
2458 this attribute to work correctly.
2460 Please refer the example of M16C target, to see the use of this
2461 attribute while declaring a function,
2463 In an application, for a function being called once, this attribute will
2464 save at least 8 bytes of code; and if other successive calls are being
2465 made to the same function, it will save 2 bytes of code per each of these
2468 On M16C/M32C targets, the @code{function_vector} attribute declares a
2469 special page subroutine call function. Use of this attribute reduces
2470 the code size by 2 bytes for each call generated to the
2471 subroutine. The argument to the attribute is the vector number entry
2472 from the special page vector table which contains the 16 low-order
2473 bits of the subroutine's entry address. Each vector table has special
2474 page number (18 to 255) which are used in @code{jsrs} instruction.
2475 Jump addresses of the routines are generated by adding 0x0F0000 (in
2476 case of M16C targets) or 0xFF0000 (in case of M32C targets), to the 2
2477 byte addresses set in the vector table. Therefore you need to ensure
2478 that all the special page vector routines should get mapped within the
2479 address range 0x0F0000 to 0x0FFFFF (for M16C) and 0xFF0000 to 0xFFFFFF
2482 In the following example 2 bytes will be saved for each call to
2483 function @code{foo}.
2486 void foo (void) __attribute__((function_vector(0x18)));
2497 If functions are defined in one file and are called in another file,
2498 then be sure to write this declaration in both files.
2500 This attribute is ignored for R8C target.
2503 @cindex interrupt handler functions
2504 Use this attribute on the ARM, AVR, CRX, M32C, M32R/D, m68k, MeP, MIPS,
2505 RX and Xstormy16 ports to indicate that the specified function is an
2506 interrupt handler. The compiler will generate function entry and exit
2507 sequences suitable for use in an interrupt handler when this attribute
2510 Note, interrupt handlers for the Blackfin, H8/300, H8/300H, H8S, and
2511 SH processors can be specified via the @code{interrupt_handler} attribute.
2513 Note, on the AVR, interrupts will be enabled inside the function.
2515 Note, for the ARM, you can specify the kind of interrupt to be handled by
2516 adding an optional parameter to the interrupt attribute like this:
2519 void f () __attribute__ ((interrupt ("IRQ")));
2522 Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@.
2524 On ARMv7-M the interrupt type is ignored, and the attribute means the function
2525 may be called with a word aligned stack pointer.
2527 On MIPS targets, you can use the following attributes to modify the behavior
2528 of an interrupt handler:
2530 @item use_shadow_register_set
2531 @cindex @code{use_shadow_register_set} attribute
2532 Assume that the handler uses a shadow register set, instead of
2533 the main general-purpose registers.
2535 @item keep_interrupts_masked
2536 @cindex @code{keep_interrupts_masked} attribute
2537 Keep interrupts masked for the whole function. Without this attribute,
2538 GCC tries to reenable interrupts for as much of the function as it can.
2540 @item use_debug_exception_return
2541 @cindex @code{use_debug_exception_return} attribute
2542 Return using the @code{deret} instruction. Interrupt handlers that don't
2543 have this attribute return using @code{eret} instead.
2546 You can use any combination of these attributes, as shown below:
2548 void __attribute__ ((interrupt)) v0 ();
2549 void __attribute__ ((interrupt, use_shadow_register_set)) v1 ();
2550 void __attribute__ ((interrupt, keep_interrupts_masked)) v2 ();
2551 void __attribute__ ((interrupt, use_debug_exception_return)) v3 ();
2552 void __attribute__ ((interrupt, use_shadow_register_set,
2553 keep_interrupts_masked)) v4 ();
2554 void __attribute__ ((interrupt, use_shadow_register_set,
2555 use_debug_exception_return)) v5 ();
2556 void __attribute__ ((interrupt, keep_interrupts_masked,
2557 use_debug_exception_return)) v6 ();
2558 void __attribute__ ((interrupt, use_shadow_register_set,
2559 keep_interrupts_masked,
2560 use_debug_exception_return)) v7 ();
2563 @item interrupt_handler
2564 @cindex interrupt handler functions on the Blackfin, m68k, H8/300 and SH processors
2565 Use this attribute on the Blackfin, m68k, H8/300, H8/300H, H8S, and SH to
2566 indicate that the specified function is an interrupt handler. The compiler
2567 will generate function entry and exit sequences suitable for use in an
2568 interrupt handler when this attribute is present.
2570 @item interrupt_thread
2571 @cindex interrupt thread functions on fido
2572 Use this attribute on fido, a subarchitecture of the m68k, to indicate
2573 that the specified function is an interrupt handler that is designed
2574 to run as a thread. The compiler omits generate prologue/epilogue
2575 sequences and replaces the return instruction with a @code{sleep}
2576 instruction. This attribute is available only on fido.
2579 @cindex interrupt service routines on ARM
2580 Use this attribute on ARM to write Interrupt Service Routines. This is an
2581 alias to the @code{interrupt} attribute above.
2584 @cindex User stack pointer in interrupts on the Blackfin
2585 When used together with @code{interrupt_handler}, @code{exception_handler}
2586 or @code{nmi_handler}, code will be generated to load the stack pointer
2587 from the USP register in the function prologue.
2590 @cindex @code{l1_text} function attribute
2591 This attribute specifies a function to be placed into L1 Instruction
2592 SRAM@. The function will be put into a specific section named @code{.l1.text}.
2593 With @option{-mfdpic}, function calls with a such function as the callee
2594 or caller will use inlined PLT.
2597 @cindex @code{l2} function attribute
2598 On the Blackfin, this attribute specifies a function to be placed into L2
2599 SRAM. The function will be put into a specific section named
2600 @code{.l1.text}. With @option{-mfdpic}, callers of such functions will use
2603 @item long_call/short_call
2604 @cindex indirect calls on ARM
2605 This attribute specifies how a particular function is called on
2606 ARM@. Both attributes override the @option{-mlong-calls} (@pxref{ARM Options})
2607 command line switch and @code{#pragma long_calls} settings. The
2608 @code{long_call} attribute indicates that the function might be far
2609 away from the call site and require a different (more expensive)
2610 calling sequence. The @code{short_call} attribute always places
2611 the offset to the function from the call site into the @samp{BL}
2612 instruction directly.
2614 @item longcall/shortcall
2615 @cindex functions called via pointer on the RS/6000 and PowerPC
2616 On the Blackfin, RS/6000 and PowerPC, the @code{longcall} attribute
2617 indicates that the function might be far away from the call site and
2618 require a different (more expensive) calling sequence. The
2619 @code{shortcall} attribute indicates that the function is always close
2620 enough for the shorter calling sequence to be used. These attributes
2621 override both the @option{-mlongcall} switch and, on the RS/6000 and
2622 PowerPC, the @code{#pragma longcall} setting.
2624 @xref{RS/6000 and PowerPC Options}, for more information on whether long
2625 calls are necessary.
2627 @item long_call/near/far
2628 @cindex indirect calls on MIPS
2629 These attributes specify how a particular function is called on MIPS@.
2630 The attributes override the @option{-mlong-calls} (@pxref{MIPS Options})
2631 command-line switch. The @code{long_call} and @code{far} attributes are
2632 synonyms, and cause the compiler to always call
2633 the function by first loading its address into a register, and then using
2634 the contents of that register. The @code{near} attribute has the opposite
2635 effect; it specifies that non-PIC calls should be made using the more
2636 efficient @code{jal} instruction.
2639 @cindex @code{malloc} attribute
2640 The @code{malloc} attribute is used to tell the compiler that a function
2641 may be treated as if any non-@code{NULL} pointer it returns cannot
2642 alias any other pointer valid when the function returns.
2643 This will often improve optimization.
2644 Standard functions with this property include @code{malloc} and
2645 @code{calloc}. @code{realloc}-like functions have this property as
2646 long as the old pointer is never referred to (including comparing it
2647 to the new pointer) after the function returns a non-@code{NULL}
2650 @item mips16/nomips16
2651 @cindex @code{mips16} attribute
2652 @cindex @code{nomips16} attribute
2654 On MIPS targets, you can use the @code{mips16} and @code{nomips16}
2655 function attributes to locally select or turn off MIPS16 code generation.
2656 A function with the @code{mips16} attribute is emitted as MIPS16 code,
2657 while MIPS16 code generation is disabled for functions with the
2658 @code{nomips16} attribute. These attributes override the
2659 @option{-mips16} and @option{-mno-mips16} options on the command line
2660 (@pxref{MIPS Options}).
2662 When compiling files containing mixed MIPS16 and non-MIPS16 code, the
2663 preprocessor symbol @code{__mips16} reflects the setting on the command line,
2664 not that within individual functions. Mixed MIPS16 and non-MIPS16 code
2665 may interact badly with some GCC extensions such as @code{__builtin_apply}
2666 (@pxref{Constructing Calls}).
2668 @item model (@var{model-name})
2669 @cindex function addressability on the M32R/D
2670 @cindex variable addressability on the IA-64
2672 On the M32R/D, use this attribute to set the addressability of an
2673 object, and of the code generated for a function. The identifier
2674 @var{model-name} is one of @code{small}, @code{medium}, or
2675 @code{large}, representing each of the code models.
2677 Small model objects live in the lower 16MB of memory (so that their
2678 addresses can be loaded with the @code{ld24} instruction), and are
2679 callable with the @code{bl} instruction.
2681 Medium model objects may live anywhere in the 32-bit address space (the
2682 compiler will generate @code{seth/add3} instructions to load their addresses),
2683 and are callable with the @code{bl} instruction.
2685 Large model objects may live anywhere in the 32-bit address space (the
2686 compiler will generate @code{seth/add3} instructions to load their addresses),
2687 and may not be reachable with the @code{bl} instruction (the compiler will
2688 generate the much slower @code{seth/add3/jl} instruction sequence).
2690 On IA-64, use this attribute to set the addressability of an object.
2691 At present, the only supported identifier for @var{model-name} is
2692 @code{small}, indicating addressability via ``small'' (22-bit)
2693 addresses (so that their addresses can be loaded with the @code{addl}
2694 instruction). Caveat: such addressing is by definition not position
2695 independent and hence this attribute must not be used for objects
2696 defined by shared libraries.
2698 @item ms_abi/sysv_abi
2699 @cindex @code{ms_abi} attribute
2700 @cindex @code{sysv_abi} attribute
2702 On 64-bit x86_64-*-* targets, you can use an ABI attribute to indicate
2703 which calling convention should be used for a function. The @code{ms_abi}
2704 attribute tells the compiler to use the Microsoft ABI, while the
2705 @code{sysv_abi} attribute tells the compiler to use the ABI used on
2706 GNU/Linux and other systems. The default is to use the Microsoft ABI
2707 when targeting Windows. On all other systems, the default is the AMD ABI.
2709 Note, This feature is currently sorried out for Windows targets trying to
2711 @item ms_hook_prologue
2712 @cindex @code{ms_hook_prologue} attribute
2714 On 32 bit i[34567]86-*-* targets, you can use this function attribute to make
2715 gcc generate the "hot-patching" function prologue used in Win32 API
2716 functions in Microsoft Windows XP Service Pack 2 and newer. This requires
2717 support for the swap suffix in the assembler. (GNU Binutils 2.19.51 or later)
2720 @cindex function without a prologue/epilogue code
2721 Use this attribute on the ARM, AVR, IP2K, RX and SPU ports to indicate that
2722 the specified function does not need prologue/epilogue sequences generated by
2723 the compiler. It is up to the programmer to provide these sequences. The
2724 only statements that can be safely included in naked functions are
2725 @code{asm} statements that do not have operands. All other statements,
2726 including declarations of local variables, @code{if} statements, and so
2727 forth, should be avoided. Naked functions should be used to implement the
2728 body of an assembly function, while allowing the compiler to construct
2729 the requisite function declaration for the assembler.
2732 @cindex functions which do not handle memory bank switching on 68HC11/68HC12
2733 On 68HC11 and 68HC12 the @code{near} attribute causes the compiler to
2734 use the normal calling convention based on @code{jsr} and @code{rts}.
2735 This attribute can be used to cancel the effect of the @option{-mlong-calls}
2738 On MeP targets this attribute causes the compiler to assume the called
2739 function is close enough to use the normal calling convention,
2740 overriding the @code{-mtf} command line option.
2743 @cindex Allow nesting in an interrupt handler on the Blackfin processor.
2744 Use this attribute together with @code{interrupt_handler},
2745 @code{exception_handler} or @code{nmi_handler} to indicate that the function
2746 entry code should enable nested interrupts or exceptions.
2749 @cindex NMI handler functions on the Blackfin processor
2750 Use this attribute on the Blackfin to indicate that the specified function
2751 is an NMI handler. The compiler will generate function entry and
2752 exit sequences suitable for use in an NMI handler when this
2753 attribute is present.
2755 @item no_instrument_function
2756 @cindex @code{no_instrument_function} function attribute
2757 @opindex finstrument-functions
2758 If @option{-finstrument-functions} is given, profiling function calls will
2759 be generated at entry and exit of most user-compiled functions.
2760 Functions with this attribute will not be so instrumented.
2763 @cindex @code{noinline} function attribute
2764 This function attribute prevents a function from being considered for
2766 @c Don't enumerate the optimizations by name here; we try to be
2767 @c future-compatible with this mechanism.
2768 If the function does not have side-effects, there are optimizations
2769 other than inlining that causes function calls to be optimized away,
2770 although the function call is live. To keep such calls from being
2775 (@pxref{Extended Asm}) in the called function, to serve as a special
2779 @cindex @code{noclone} function attribute
2780 This function attribute prevents a function from being considered for
2781 cloning - a mechanism which produces specialized copies of functions
2782 and which is (currently) performed by interprocedural constant
2785 @item nonnull (@var{arg-index}, @dots{})
2786 @cindex @code{nonnull} function attribute
2787 The @code{nonnull} attribute specifies that some function parameters should
2788 be non-null pointers. For instance, the declaration:
2792 my_memcpy (void *dest, const void *src, size_t len)
2793 __attribute__((nonnull (1, 2)));
2797 causes the compiler to check that, in calls to @code{my_memcpy},
2798 arguments @var{dest} and @var{src} are non-null. If the compiler
2799 determines that a null pointer is passed in an argument slot marked
2800 as non-null, and the @option{-Wnonnull} option is enabled, a warning
2801 is issued. The compiler may also choose to make optimizations based
2802 on the knowledge that certain function arguments will not be null.
2804 If no argument index list is given to the @code{nonnull} attribute,
2805 all pointer arguments are marked as non-null. To illustrate, the
2806 following declaration is equivalent to the previous example:
2810 my_memcpy (void *dest, const void *src, size_t len)
2811 __attribute__((nonnull));
2815 @cindex @code{noreturn} function attribute
2816 A few standard library functions, such as @code{abort} and @code{exit},
2817 cannot return. GCC knows this automatically. Some programs define
2818 their own functions that never return. You can declare them
2819 @code{noreturn} to tell the compiler this fact. For example,
2823 void fatal () __attribute__ ((noreturn));
2826 fatal (/* @r{@dots{}} */)
2828 /* @r{@dots{}} */ /* @r{Print error message.} */ /* @r{@dots{}} */
2834 The @code{noreturn} keyword tells the compiler to assume that
2835 @code{fatal} cannot return. It can then optimize without regard to what
2836 would happen if @code{fatal} ever did return. This makes slightly
2837 better code. More importantly, it helps avoid spurious warnings of
2838 uninitialized variables.
2840 The @code{noreturn} keyword does not affect the exceptional path when that
2841 applies: a @code{noreturn}-marked function may still return to the caller
2842 by throwing an exception or calling @code{longjmp}.
2844 Do not assume that registers saved by the calling function are
2845 restored before calling the @code{noreturn} function.
2847 It does not make sense for a @code{noreturn} function to have a return
2848 type other than @code{void}.
2850 The attribute @code{noreturn} is not implemented in GCC versions
2851 earlier than 2.5. An alternative way to declare that a function does
2852 not return, which works in the current version and in some older
2853 versions, is as follows:
2856 typedef void voidfn ();
2858 volatile voidfn fatal;
2861 This approach does not work in GNU C++.
2864 @cindex @code{nothrow} function attribute
2865 The @code{nothrow} attribute is used to inform the compiler that a
2866 function cannot throw an exception. For example, most functions in
2867 the standard C library can be guaranteed not to throw an exception
2868 with the notable exceptions of @code{qsort} and @code{bsearch} that
2869 take function pointer arguments. The @code{nothrow} attribute is not
2870 implemented in GCC versions earlier than 3.3.
2873 @cindex @code{optimize} function attribute
2874 The @code{optimize} attribute is used to specify that a function is to
2875 be compiled with different optimization options than specified on the
2876 command line. Arguments can either be numbers or strings. Numbers
2877 are assumed to be an optimization level. Strings that begin with
2878 @code{O} are assumed to be an optimization option, while other options
2879 are assumed to be used with a @code{-f} prefix. You can also use the
2880 @samp{#pragma GCC optimize} pragma to set the optimization options
2881 that affect more than one function.
2882 @xref{Function Specific Option Pragmas}, for details about the
2883 @samp{#pragma GCC optimize} pragma.
2885 This can be used for instance to have frequently executed functions
2886 compiled with more aggressive optimization options that produce faster
2887 and larger code, while other functions can be called with less
2891 @cindex @code{pcs} function attribute
2893 The @code{pcs} attribute can be used to control the calling convention
2894 used for a function on ARM. The attribute takes an argument that specifies
2895 the calling convention to use.
2897 When compiling using the AAPCS ABI (or a variant of that) then valid
2898 values for the argument are @code{"aapcs"} and @code{"aapcs-vfp"}. In
2899 order to use a variant other than @code{"aapcs"} then the compiler must
2900 be permitted to use the appropriate co-processor registers (i.e., the
2901 VFP registers must be available in order to use @code{"aapcs-vfp"}).
2905 /* Argument passed in r0, and result returned in r0+r1. */
2906 double f2d (float) __attribute__((pcs("aapcs")));
2909 Variadic functions always use the @code{"aapcs"} calling convention and
2910 the compiler will reject attempts to specify an alternative.
2913 @cindex @code{pure} function attribute
2914 Many functions have no effects except the return value and their
2915 return value depends only on the parameters and/or global variables.
2916 Such a function can be subject
2917 to common subexpression elimination and loop optimization just as an
2918 arithmetic operator would be. These functions should be declared
2919 with the attribute @code{pure}. For example,
2922 int square (int) __attribute__ ((pure));
2926 says that the hypothetical function @code{square} is safe to call
2927 fewer times than the program says.
2929 Some of common examples of pure functions are @code{strlen} or @code{memcmp}.
2930 Interesting non-pure functions are functions with infinite loops or those
2931 depending on volatile memory or other system resource, that may change between
2932 two consecutive calls (such as @code{feof} in a multithreading environment).
2934 The attribute @code{pure} is not implemented in GCC versions earlier
2938 @cindex @code{hot} function attribute
2939 The @code{hot} attribute is used to inform the compiler that a function is a
2940 hot spot of the compiled program. The function is optimized more aggressively
2941 and on many target it is placed into special subsection of the text section so
2942 all hot functions appears close together improving locality.
2944 When profile feedback is available, via @option{-fprofile-use}, hot functions
2945 are automatically detected and this attribute is ignored.
2947 The @code{hot} attribute is not implemented in GCC versions earlier
2951 @cindex @code{cold} function attribute
2952 The @code{cold} attribute is used to inform the compiler that a function is
2953 unlikely executed. The function is optimized for size rather than speed and on
2954 many targets it is placed into special subsection of the text section so all
2955 cold functions appears close together improving code locality of non-cold parts
2956 of program. The paths leading to call of cold functions within code are marked
2957 as unlikely by the branch prediction mechanism. It is thus useful to mark
2958 functions used to handle unlikely conditions, such as @code{perror}, as cold to
2959 improve optimization of hot functions that do call marked functions in rare
2962 When profile feedback is available, via @option{-fprofile-use}, hot functions
2963 are automatically detected and this attribute is ignored.
2965 The @code{cold} attribute is not implemented in GCC versions earlier than 4.3.
2967 @item regparm (@var{number})
2968 @cindex @code{regparm} attribute
2969 @cindex functions that are passed arguments in registers on the 386
2970 On the Intel 386, the @code{regparm} attribute causes the compiler to
2971 pass arguments number one to @var{number} if they are of integral type
2972 in registers EAX, EDX, and ECX instead of on the stack. Functions that
2973 take a variable number of arguments will continue to be passed all of their
2974 arguments on the stack.
2976 Beware that on some ELF systems this attribute is unsuitable for
2977 global functions in shared libraries with lazy binding (which is the
2978 default). Lazy binding will send the first call via resolving code in
2979 the loader, which might assume EAX, EDX and ECX can be clobbered, as
2980 per the standard calling conventions. Solaris 8 is affected by this.
2981 GNU systems with GLIBC 2.1 or higher, and FreeBSD, are believed to be
2982 safe since the loaders there save EAX, EDX and ECX. (Lazy binding can be
2983 disabled with the linker or the loader if desired, to avoid the
2987 @cindex @code{sseregparm} attribute
2988 On the Intel 386 with SSE support, the @code{sseregparm} attribute
2989 causes the compiler to pass up to 3 floating point arguments in
2990 SSE registers instead of on the stack. Functions that take a
2991 variable number of arguments will continue to pass all of their
2992 floating point arguments on the stack.
2994 @item force_align_arg_pointer
2995 @cindex @code{force_align_arg_pointer} attribute
2996 On the Intel x86, the @code{force_align_arg_pointer} attribute may be
2997 applied to individual function definitions, generating an alternate
2998 prologue and epilogue that realigns the runtime stack if necessary.
2999 This supports mixing legacy codes that run with a 4-byte aligned stack
3000 with modern codes that keep a 16-byte stack for SSE compatibility.
3003 @cindex @code{resbank} attribute
3004 On the SH2A target, this attribute enables the high-speed register
3005 saving and restoration using a register bank for @code{interrupt_handler}
3006 routines. Saving to the bank is performed automatically after the CPU
3007 accepts an interrupt that uses a register bank.
3009 The nineteen 32-bit registers comprising general register R0 to R14,
3010 control register GBR, and system registers MACH, MACL, and PR and the
3011 vector table address offset are saved into a register bank. Register
3012 banks are stacked in first-in last-out (FILO) sequence. Restoration
3013 from the bank is executed by issuing a RESBANK instruction.
3016 @cindex @code{returns_twice} attribute
3017 The @code{returns_twice} attribute tells the compiler that a function may
3018 return more than one time. The compiler will ensure that all registers
3019 are dead before calling such a function and will emit a warning about
3020 the variables that may be clobbered after the second return from the
3021 function. Examples of such functions are @code{setjmp} and @code{vfork}.
3022 The @code{longjmp}-like counterpart of such function, if any, might need
3023 to be marked with the @code{noreturn} attribute.
3026 @cindex save all registers on the Blackfin, H8/300, H8/300H, and H8S
3027 Use this attribute on the Blackfin, H8/300, H8/300H, and H8S to indicate that
3028 all registers except the stack pointer should be saved in the prologue
3029 regardless of whether they are used or not.
3031 @item section ("@var{section-name}")
3032 @cindex @code{section} function attribute
3033 Normally, the compiler places the code it generates in the @code{text} section.
3034 Sometimes, however, you need additional sections, or you need certain
3035 particular functions to appear in special sections. The @code{section}
3036 attribute specifies that a function lives in a particular section.
3037 For example, the declaration:
3040 extern void foobar (void) __attribute__ ((section ("bar")));
3044 puts the function @code{foobar} in the @code{bar} section.
3046 Some file formats do not support arbitrary sections so the @code{section}
3047 attribute is not available on all platforms.
3048 If you need to map the entire contents of a module to a particular
3049 section, consider using the facilities of the linker instead.
3052 @cindex @code{sentinel} function attribute
3053 This function attribute ensures that a parameter in a function call is
3054 an explicit @code{NULL}. The attribute is only valid on variadic
3055 functions. By default, the sentinel is located at position zero, the
3056 last parameter of the function call. If an optional integer position
3057 argument P is supplied to the attribute, the sentinel must be located at
3058 position P counting backwards from the end of the argument list.
3061 __attribute__ ((sentinel))
3063 __attribute__ ((sentinel(0)))
3066 The attribute is automatically set with a position of 0 for the built-in
3067 functions @code{execl} and @code{execlp}. The built-in function
3068 @code{execle} has the attribute set with a position of 1.
3070 A valid @code{NULL} in this context is defined as zero with any pointer
3071 type. If your system defines the @code{NULL} macro with an integer type
3072 then you need to add an explicit cast. GCC replaces @code{stddef.h}
3073 with a copy that redefines NULL appropriately.
3075 The warnings for missing or incorrect sentinels are enabled with
3079 See long_call/short_call.
3082 See longcall/shortcall.
3085 @cindex signal handler functions on the AVR processors
3086 Use this attribute on the AVR to indicate that the specified
3087 function is a signal handler. The compiler will generate function
3088 entry and exit sequences suitable for use in a signal handler when this
3089 attribute is present. Interrupts will be disabled inside the function.
3092 Use this attribute on the SH to indicate an @code{interrupt_handler}
3093 function should switch to an alternate stack. It expects a string
3094 argument that names a global variable holding the address of the
3099 void f () __attribute__ ((interrupt_handler,
3100 sp_switch ("alt_stack")));
3104 @cindex functions that pop the argument stack on the 386
3105 On the Intel 386, the @code{stdcall} attribute causes the compiler to
3106 assume that the called function will pop off the stack space used to
3107 pass arguments, unless it takes a variable number of arguments.
3109 @item syscall_linkage
3110 @cindex @code{syscall_linkage} attribute
3111 This attribute is used to modify the IA64 calling convention by marking
3112 all input registers as live at all function exits. This makes it possible
3113 to restart a system call after an interrupt without having to save/restore
3114 the input registers. This also prevents kernel data from leaking into
3118 @cindex @code{target} function attribute
3119 The @code{target} attribute is used to specify that a function is to
3120 be compiled with different target options than specified on the
3121 command line. This can be used for instance to have functions
3122 compiled with a different ISA (instruction set architecture) than the
3123 default. You can also use the @samp{#pragma GCC target} pragma to set
3124 more than one function to be compiled with specific target options.
3125 @xref{Function Specific Option Pragmas}, for details about the
3126 @samp{#pragma GCC target} pragma.
3128 For instance on a 386, you could compile one function with
3129 @code{target("sse4.1,arch=core2")} and another with
3130 @code{target("sse4a,arch=amdfam10")} that would be equivalent to
3131 compiling the first function with @option{-msse4.1} and
3132 @option{-march=core2} options, and the second function with
3133 @option{-msse4a} and @option{-march=amdfam10} options. It is up to the
3134 user to make sure that a function is only invoked on a machine that
3135 supports the particular ISA it was compiled for (for example by using
3136 @code{cpuid} on 386 to determine what feature bits and architecture
3140 int core2_func (void) __attribute__ ((__target__ ("arch=core2")));
3141 int sse3_func (void) __attribute__ ((__target__ ("sse3")));
3144 On the 386, the following options are allowed:
3149 @cindex @code{target("abm")} attribute
3150 Enable/disable the generation of the advanced bit instructions.
3154 @cindex @code{target("aes")} attribute
3155 Enable/disable the generation of the AES instructions.
3159 @cindex @code{target("mmx")} attribute
3160 Enable/disable the generation of the MMX instructions.
3164 @cindex @code{target("pclmul")} attribute
3165 Enable/disable the generation of the PCLMUL instructions.
3169 @cindex @code{target("popcnt")} attribute
3170 Enable/disable the generation of the POPCNT instruction.
3174 @cindex @code{target("sse")} attribute
3175 Enable/disable the generation of the SSE instructions.
3179 @cindex @code{target("sse2")} attribute
3180 Enable/disable the generation of the SSE2 instructions.
3184 @cindex @code{target("sse3")} attribute
3185 Enable/disable the generation of the SSE3 instructions.
3189 @cindex @code{target("sse4")} attribute
3190 Enable/disable the generation of the SSE4 instructions (both SSE4.1
3195 @cindex @code{target("sse4.1")} attribute
3196 Enable/disable the generation of the sse4.1 instructions.
3200 @cindex @code{target("sse4.2")} attribute
3201 Enable/disable the generation of the sse4.2 instructions.
3205 @cindex @code{target("sse4a")} attribute
3206 Enable/disable the generation of the SSE4A instructions.
3210 @cindex @code{target("fma4")} attribute
3211 Enable/disable the generation of the FMA4 instructions.
3215 @cindex @code{target("xop")} attribute
3216 Enable/disable the generation of the XOP instructions.
3220 @cindex @code{target("lwp")} attribute
3221 Enable/disable the generation of the LWP instructions.
3225 @cindex @code{target("ssse3")} attribute
3226 Enable/disable the generation of the SSSE3 instructions.
3230 @cindex @code{target("cld")} attribute
3231 Enable/disable the generation of the CLD before string moves.
3233 @item fancy-math-387
3234 @itemx no-fancy-math-387
3235 @cindex @code{target("fancy-math-387")} attribute
3236 Enable/disable the generation of the @code{sin}, @code{cos}, and
3237 @code{sqrt} instructions on the 387 floating point unit.
3240 @itemx no-fused-madd
3241 @cindex @code{target("fused-madd")} attribute
3242 Enable/disable the generation of the fused multiply/add instructions.
3246 @cindex @code{target("ieee-fp")} attribute
3247 Enable/disable the generation of floating point that depends on IEEE arithmetic.
3249 @item inline-all-stringops
3250 @itemx no-inline-all-stringops
3251 @cindex @code{target("inline-all-stringops")} attribute
3252 Enable/disable inlining of string operations.
3254 @item inline-stringops-dynamically
3255 @itemx no-inline-stringops-dynamically
3256 @cindex @code{target("inline-stringops-dynamically")} attribute
3257 Enable/disable the generation of the inline code to do small string
3258 operations and calling the library routines for large operations.
3260 @item align-stringops
3261 @itemx no-align-stringops
3262 @cindex @code{target("align-stringops")} attribute
3263 Do/do not align destination of inlined string operations.
3267 @cindex @code{target("recip")} attribute
3268 Enable/disable the generation of RCPSS, RCPPS, RSQRTSS and RSQRTPS
3269 instructions followed an additional Newton-Raphson step instead of
3270 doing a floating point division.
3272 @item arch=@var{ARCH}
3273 @cindex @code{target("arch=@var{ARCH}")} attribute
3274 Specify the architecture to generate code for in compiling the function.
3276 @item tune=@var{TUNE}
3277 @cindex @code{target("tune=@var{TUNE}")} attribute
3278 Specify the architecture to tune for in compiling the function.
3280 @item fpmath=@var{FPMATH}
3281 @cindex @code{target("fpmath=@var{FPMATH}")} attribute
3282 Specify which floating point unit to use. The
3283 @code{target("fpmath=sse,387")} option must be specified as
3284 @code{target("fpmath=sse+387")} because the comma would separate
3288 On the 386, you can use either multiple strings to specify multiple
3289 options, or you can separate the option with a comma (@code{,}).
3291 On the 386, the inliner will not inline a function that has different
3292 target options than the caller, unless the callee has a subset of the
3293 target options of the caller. For example a function declared with
3294 @code{target("sse3")} can inline a function with
3295 @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}.
3297 The @code{target} attribute is not implemented in GCC versions earlier
3298 than 4.4, and at present only the 386 uses it.
3301 @cindex tiny data section on the H8/300H and H8S
3302 Use this attribute on the H8/300H and H8S to indicate that the specified
3303 variable should be placed into the tiny data section.
3304 The compiler will generate more efficient code for loads and stores
3305 on data in the tiny data section. Note the tiny data area is limited to
3306 slightly under 32kbytes of data.
3309 Use this attribute on the SH for an @code{interrupt_handler} to return using
3310 @code{trapa} instead of @code{rte}. This attribute expects an integer
3311 argument specifying the trap number to be used.
3314 @cindex @code{unused} attribute.
3315 This attribute, attached to a function, means that the function is meant
3316 to be possibly unused. GCC will not produce a warning for this
3320 @cindex @code{used} attribute.
3321 This attribute, attached to a function, means that code must be emitted
3322 for the function even if it appears that the function is not referenced.
3323 This is useful, for example, when the function is referenced only in
3327 @cindex @code{version_id} attribute
3328 This IA64 HP-UX attribute, attached to a global variable or function, renames a
3329 symbol to contain a version string, thus allowing for function level
3330 versioning. HP-UX system header files may use version level functioning
3331 for some system calls.
3334 extern int foo () __attribute__((version_id ("20040821")));
3337 Calls to @var{foo} will be mapped to calls to @var{foo@{20040821@}}.
3339 @item visibility ("@var{visibility_type}")
3340 @cindex @code{visibility} attribute
3341 This attribute affects the linkage of the declaration to which it is attached.
3342 There are four supported @var{visibility_type} values: default,
3343 hidden, protected or internal visibility.
3346 void __attribute__ ((visibility ("protected")))
3347 f () @{ /* @r{Do something.} */; @}
3348 int i __attribute__ ((visibility ("hidden")));
3351 The possible values of @var{visibility_type} correspond to the
3352 visibility settings in the ELF gABI.
3355 @c keep this list of visibilities in alphabetical order.
3358 Default visibility is the normal case for the object file format.
3359 This value is available for the visibility attribute to override other
3360 options that may change the assumed visibility of entities.
3362 On ELF, default visibility means that the declaration is visible to other
3363 modules and, in shared libraries, means that the declared entity may be
3366 On Darwin, default visibility means that the declaration is visible to
3369 Default visibility corresponds to ``external linkage'' in the language.
3372 Hidden visibility indicates that the entity declared will have a new
3373 form of linkage, which we'll call ``hidden linkage''. Two
3374 declarations of an object with hidden linkage refer to the same object
3375 if they are in the same shared object.
3378 Internal visibility is like hidden visibility, but with additional
3379 processor specific semantics. Unless otherwise specified by the
3380 psABI, GCC defines internal visibility to mean that a function is
3381 @emph{never} called from another module. Compare this with hidden
3382 functions which, while they cannot be referenced directly by other
3383 modules, can be referenced indirectly via function pointers. By
3384 indicating that a function cannot be called from outside the module,
3385 GCC may for instance omit the load of a PIC register since it is known
3386 that the calling function loaded the correct value.
3389 Protected visibility is like default visibility except that it
3390 indicates that references within the defining module will bind to the
3391 definition in that module. That is, the declared entity cannot be
3392 overridden by another module.
3396 All visibilities are supported on many, but not all, ELF targets
3397 (supported when the assembler supports the @samp{.visibility}
3398 pseudo-op). Default visibility is supported everywhere. Hidden
3399 visibility is supported on Darwin targets.
3401 The visibility attribute should be applied only to declarations which
3402 would otherwise have external linkage. The attribute should be applied
3403 consistently, so that the same entity should not be declared with
3404 different settings of the attribute.
3406 In C++, the visibility attribute applies to types as well as functions
3407 and objects, because in C++ types have linkage. A class must not have
3408 greater visibility than its non-static data member types and bases,
3409 and class members default to the visibility of their class. Also, a
3410 declaration without explicit visibility is limited to the visibility
3413 In C++, you can mark member functions and static member variables of a
3414 class with the visibility attribute. This is useful if you know a
3415 particular method or static member variable should only be used from
3416 one shared object; then you can mark it hidden while the rest of the
3417 class has default visibility. Care must be taken to avoid breaking
3418 the One Definition Rule; for example, it is usually not useful to mark
3419 an inline method as hidden without marking the whole class as hidden.
3421 A C++ namespace declaration can also have the visibility attribute.
3422 This attribute applies only to the particular namespace body, not to
3423 other definitions of the same namespace; it is equivalent to using
3424 @samp{#pragma GCC visibility} before and after the namespace
3425 definition (@pxref{Visibility Pragmas}).
3427 In C++, if a template argument has limited visibility, this
3428 restriction is implicitly propagated to the template instantiation.
3429 Otherwise, template instantiations and specializations default to the
3430 visibility of their template.
3432 If both the template and enclosing class have explicit visibility, the
3433 visibility from the template is used.
3436 @cindex @code{vliw} attribute
3437 On MeP, the @code{vliw} attribute tells the compiler to emit
3438 instructions in VLIW mode instead of core mode. Note that this
3439 attribute is not allowed unless a VLIW coprocessor has been configured
3440 and enabled through command line options.
3442 @item warn_unused_result
3443 @cindex @code{warn_unused_result} attribute
3444 The @code{warn_unused_result} attribute causes a warning to be emitted
3445 if a caller of the function with this attribute does not use its
3446 return value. This is useful for functions where not checking
3447 the result is either a security problem or always a bug, such as
3451 int fn () __attribute__ ((warn_unused_result));
3454 if (fn () < 0) return -1;
3460 results in warning on line 5.
3463 @cindex @code{weak} attribute
3464 The @code{weak} attribute causes the declaration to be emitted as a weak
3465 symbol rather than a global. This is primarily useful in defining
3466 library functions which can be overridden in user code, though it can
3467 also be used with non-function declarations. Weak symbols are supported
3468 for ELF targets, and also for a.out targets when using the GNU assembler
3472 @itemx weakref ("@var{target}")
3473 @cindex @code{weakref} attribute
3474 The @code{weakref} attribute marks a declaration as a weak reference.
3475 Without arguments, it should be accompanied by an @code{alias} attribute
3476 naming the target symbol. Optionally, the @var{target} may be given as
3477 an argument to @code{weakref} itself. In either case, @code{weakref}
3478 implicitly marks the declaration as @code{weak}. Without a
3479 @var{target}, given as an argument to @code{weakref} or to @code{alias},
3480 @code{weakref} is equivalent to @code{weak}.
3483 static int x() __attribute__ ((weakref ("y")));
3484 /* is equivalent to... */
3485 static int x() __attribute__ ((weak, weakref, alias ("y")));
3487 static int x() __attribute__ ((weakref));
3488 static int x() __attribute__ ((alias ("y")));
3491 A weak reference is an alias that does not by itself require a
3492 definition to be given for the target symbol. If the target symbol is
3493 only referenced through weak references, then the becomes a @code{weak}
3494 undefined symbol. If it is directly referenced, however, then such
3495 strong references prevail, and a definition will be required for the
3496 symbol, not necessarily in the same translation unit.
3498 The effect is equivalent to moving all references to the alias to a
3499 separate translation unit, renaming the alias to the aliased symbol,
3500 declaring it as weak, compiling the two separate translation units and
3501 performing a reloadable link on them.
3503 At present, a declaration to which @code{weakref} is attached can
3504 only be @code{static}.
3508 You can specify multiple attributes in a declaration by separating them
3509 by commas within the double parentheses or by immediately following an
3510 attribute declaration with another attribute declaration.
3512 @cindex @code{#pragma}, reason for not using
3513 @cindex pragma, reason for not using
3514 Some people object to the @code{__attribute__} feature, suggesting that
3515 ISO C's @code{#pragma} should be used instead. At the time
3516 @code{__attribute__} was designed, there were two reasons for not doing
3521 It is impossible to generate @code{#pragma} commands from a macro.
3524 There is no telling what the same @code{#pragma} might mean in another
3528 These two reasons applied to almost any application that might have been
3529 proposed for @code{#pragma}. It was basically a mistake to use
3530 @code{#pragma} for @emph{anything}.
3532 The ISO C99 standard includes @code{_Pragma}, which now allows pragmas
3533 to be generated from macros. In addition, a @code{#pragma GCC}
3534 namespace is now in use for GCC-specific pragmas. However, it has been
3535 found convenient to use @code{__attribute__} to achieve a natural
3536 attachment of attributes to their corresponding declarations, whereas
3537 @code{#pragma GCC} is of use for constructs that do not naturally form
3538 part of the grammar. @xref{Other Directives,,Miscellaneous
3539 Preprocessing Directives, cpp, The GNU C Preprocessor}.
3541 @node Attribute Syntax
3542 @section Attribute Syntax
3543 @cindex attribute syntax
3545 This section describes the syntax with which @code{__attribute__} may be
3546 used, and the constructs to which attribute specifiers bind, for the C
3547 language. Some details may vary for C++ and Objective-C@. Because of
3548 infelicities in the grammar for attributes, some forms described here
3549 may not be successfully parsed in all cases.
3551 There are some problems with the semantics of attributes in C++. For
3552 example, there are no manglings for attributes, although they may affect
3553 code generation, so problems may arise when attributed types are used in
3554 conjunction with templates or overloading. Similarly, @code{typeid}
3555 does not distinguish between types with different attributes. Support
3556 for attributes in C++ may be restricted in future to attributes on
3557 declarations only, but not on nested declarators.
3559 @xref{Function Attributes}, for details of the semantics of attributes
3560 applying to functions. @xref{Variable Attributes}, for details of the
3561 semantics of attributes applying to variables. @xref{Type Attributes},
3562 for details of the semantics of attributes applying to structure, union
3563 and enumerated types.
3565 An @dfn{attribute specifier} is of the form
3566 @code{__attribute__ ((@var{attribute-list}))}. An @dfn{attribute list}
3567 is a possibly empty comma-separated sequence of @dfn{attributes}, where
3568 each attribute is one of the following:
3572 Empty. Empty attributes are ignored.
3575 A word (which may be an identifier such as @code{unused}, or a reserved
3576 word such as @code{const}).
3579 A word, followed by, in parentheses, parameters for the attribute.
3580 These parameters take one of the following forms:
3584 An identifier. For example, @code{mode} attributes use this form.
3587 An identifier followed by a comma and a non-empty comma-separated list
3588 of expressions. For example, @code{format} attributes use this form.
3591 A possibly empty comma-separated list of expressions. For example,
3592 @code{format_arg} attributes use this form with the list being a single
3593 integer constant expression, and @code{alias} attributes use this form
3594 with the list being a single string constant.