-@c Copyright (C) 1988,1989,1992,1993,1994,1996,1998,1999,2000,2001,2002, 2003
+@c Copyright (C) 1988,1989,1992,1993,1994,1996,1998,1999,2000,2001,2002,2003,2004
@c Free Software Foundation, Inc.
@c This is part of the GCC manual.
@c For copying conditions, see the file gcc.texi.
@itemize @bullet
@item
-When used as part of the register variable extension, see
+When used as part of the register variable extension, see
@ref{Explicit Reg Vars}.
@item
* Nested Functions:: As in Algol and Pascal, lexical scoping of functions.
* Constructing Calls:: Dispatching a call to another function.
* Typeof:: @code{typeof}: referring to the type of an expression.
-* Lvalues:: Using @samp{?:}, @samp{,} and casts in lvalues.
* Conditionals:: Omitting the middle operand of a @samp{?:} expression.
* Long Long:: Double-word integers---@code{long long int}.
* Complex:: Data types for complex numbers.
by braces; in this construct, parentheses go around the braces. For
example:
-@example
+@smallexample
(@{ int y = foo (); int z;
if (y > 0) z = y;
else z = - y;
z; @})
-@end example
+@end smallexample
@noindent
is a valid (though slightly more complex than necessary) expression
``maximum'' function is commonly defined as a macro in standard C as
follows:
-@example
+@smallexample
#define max(a,b) ((a) > (b) ? (a) : (b))
-@end example
+@end smallexample
@noindent
@cindex side effects, macro argument
type of the operands (here let's assume @code{int}), you can define
the macro safely as follows:
-@example
+@smallexample
#define maxint(a,b) \
(@{int _a = (a), _b = (b); _a > _b ? _a : _b; @})
-@end example
+@end smallexample
Embedded statements are not allowed in constant expressions, such as
the value of an enumeration constant, the width of a bit-field, or
GCC allows you to declare @dfn{local labels} in any nested block
scope. A local label is just like an ordinary label, but you can
only reference it (with a @code{goto} statement, or by taking its
-address) within the block in which it was declared.
+address) within the block in which it was declared.
A local label declaration looks like this:
-@example
+@smallexample
__label__ @var{label};
-@end example
+@end smallexample
@noindent
or
-@example
+@smallexample
__label__ @var{label1}, @var{label2}, /* @r{@dots{}} */;
-@end example
+@end smallexample
Local label declarations must come at the beginning of the block,
before any ordinary declarations or statements.
function, the label will be multiply defined in that function. A
local label avoids this problem. For example:
-@example
+@smallexample
#define SEARCH(value, array, target) \
do @{ \
__label__ found; \
(value) = -1; \
found:; \
@} while (0)
-@end example
+@end smallexample
This could also be written using a statement-expression:
-@example
+@smallexample
#define SEARCH(array, target) \
(@{ \
__label__ found; \
found: \
value; \
@})
-@end example
+@end smallexample
Local label declarations also make the labels they declare visible to
nested functions, if there are any. @xref{Nested Functions}, for details.
value has type @code{void *}. This value is a constant and can be used
wherever a constant of that type is valid. For example:
-@example
+@smallexample
void *ptr;
/* @r{@dots{}} */
ptr = &&foo;
-@end example
+@end smallexample
To use these values, you need to be able to jump to one. This is done
with the computed goto statement@footnote{The analogous feature in
C, where one can do more than simply store label addresses in label
variables.}, @code{goto *@var{exp};}. For example,
-@example
+@smallexample
goto *ptr;
-@end example
+@end smallexample
@noindent
Any expression of type @code{void *} is allowed.
One way of using these constants is in initializing a static array that
will serve as a jump table:
-@example
+@smallexample
static void *array[] = @{ &&foo, &&bar, &&hack @};
-@end example
+@end smallexample
Then you can select a label with indexing, like this:
-@example
+@smallexample
goto *array[i];
-@end example
+@end smallexample
@noindent
Note that this does not check whether the subscript is in bounds---array
An alternate way to write the above example is
-@example
+@smallexample
static const int array[] = @{ &&foo - &&foo, &&bar - &&foo,
&&hack - &&foo @};
goto *(&&foo + array[i]);
-@end example
+@end smallexample
@noindent
This is more friendly to code living in shared libraries, as it reduces
name is local to the block where it is defined. For example, here we
define a nested function named @code{square}, and call it twice:
-@example
+@smallexample
@group
foo (double a, double b)
@{
return square (a) + square (b);
@}
@end group
-@end example
+@end smallexample
The nested function can access all the variables of the containing
function that are visible at the point of its definition. This is
called @dfn{lexical scoping}. For example, here we show a nested
function which uses an inherited variable named @code{offset}:
-@example
+@smallexample
@group
bar (int *array, int offset, int size)
@{
/* @r{@dots{}} */ access (array, i) /* @r{@dots{}} */
@}
@end group
-@end example
+@end smallexample
Nested function definitions are permitted within functions in the places
where variable definitions are allowed; that is, in any block, before
It is possible to call the nested function from outside the scope of its
name by storing its address or passing the address to another function:
-@example
+@smallexample
hack (int *array, int size)
@{
void store (int index, int value)
intermediate (store, size);
@}
-@end example
+@end smallexample
Here, the function @code{intermediate} receives the address of
@code{store} as an argument. If @code{intermediate} calls @code{store},
containing function, exiting the nested function which did the
@code{goto} and any intermediate functions as well. Here is an example:
-@example
+@smallexample
@group
bar (int *array, int offset, int size)
@{
return -1;
@}
@end group
-@end example
+@end smallexample
A nested function always has internal linkage. Declaring one with
@code{extern} is erroneous. If you need to declare the nested function
before its definition, use @code{auto} (which is otherwise meaningless
for function declarations).
-@example
+@smallexample
bar (int *array, int offset, int size)
@{
__label__ failure;
@}
/* @r{@dots{}} */
@}
-@end example
+@end smallexample
@node Constructing Calls
@section Constructing Function Calls
the function tried to return (as long as your caller expects
that data type).
+However, these built-in functions may interact badly with some
+sophisticated features or other extensions of the language. It
+is, therefore, not recommended to use them outside very simple
+functions acting as mere forwarders for their arguments.
+
@deftypefn {Built-in Function} {void *} __builtin_apply_args ()
This built-in function returns a pointer to data
describing how to perform a call with the same arguments as were passed
There are two ways of writing the argument to @code{typeof}: with an
expression or with a type. Here is an example with an expression:
-@example
+@smallexample
typeof (x[0](1))
-@end example
+@end smallexample
@noindent
This assumes that @code{x} is an array of pointers to functions;
Here is an example with a typename as the argument:
-@example
+@smallexample
typeof (int *)
-@end example
+@end smallexample
@noindent
Here the type described is that of pointers to @code{int}.
be used to define a safe ``maximum'' macro that operates on any
arithmetic type and evaluates each of its arguments exactly once:
-@example
+@smallexample
#define max(a,b) \
(@{ typeof (a) _a = (a); \
typeof (b) _b = (b); \
_a > _b ? _a : _b; @})
-@end example
+@end smallexample
@cindex underscores in variables in macros
@cindex @samp{_} in variables in macros
@item
This declares @code{y} with the type of what @code{x} points to.
-@example
+@smallexample
typeof (*x) y;
-@end example
+@end smallexample
@item
This declares @code{y} as an array of such values.
-@example
+@smallexample
typeof (*x) y[4];
-@end example
+@end smallexample
@item
This declares @code{y} as an array of pointers to characters:
-@example
+@smallexample
typeof (typeof (char *)[4]) y;
-@end example
+@end smallexample
@noindent
It is equivalent to the following traditional C declaration:
-@example
+@smallexample
char *y[4];
-@end example
+@end smallexample
To see the meaning of the declaration using @code{typeof}, and why it
might be a useful way to write, let's rewrite it with these macros:
-@example
+@smallexample
#define pointer(T) typeof(T *)
#define array(T, N) typeof(T [N])
-@end example
+@end smallexample
@noindent
Now the declaration can be rewritten this way:
-@example
+@smallexample
array (pointer (char), 4) y;
-@end example
+@end smallexample
@noindent
Thus, @code{array (pointer (char), 4)} is the type of arrays of 4
@emph{Compatibility Note:} In addition to @code{typeof}, GCC 2 supported
a more limited extension which permitted one to write
-@example
+@smallexample
typedef @var{T} = @var{expr};
-@end example
+@end smallexample
@noindent
with the effect of declaring @var{T} to have the type of the expression
3.0 and 3.2 will crash; 3.2.1 and later give an error). Code which
relies on it should be rewritten to use @code{typeof}:
-@example
+@smallexample
typedef typeof(@var{expr}) @var{T};
-@end example
+@end smallexample
@noindent
This will work with all versions of GCC@.
-@node Lvalues
-@section Generalized Lvalues
-@cindex compound expressions as lvalues
-@cindex expressions, compound, as lvalues
-@cindex conditional expressions as lvalues
-@cindex expressions, conditional, as lvalues
-@cindex casts as lvalues
-@cindex generalized lvalues
-@cindex lvalues, generalized
-@cindex extensions, @code{?:}
-@cindex @code{?:} extensions
-
-Compound expressions, conditional expressions and casts are allowed as
-lvalues provided their operands are lvalues. This means that you can take
-their addresses or store values into them.
-
-Standard C++ allows compound expressions and conditional expressions
-as lvalues, and permits casts to reference type, so use of this
-extension is not supported for C++ code.
-
-For example, a compound expression can be assigned, provided the last
-expression in the sequence is an lvalue. These two expressions are
-equivalent:
-
-@example
-(a, b) += 5
-a, (b += 5)
-@end example
-
-Similarly, the address of the compound expression can be taken. These two
-expressions are equivalent:
-
-@example
-&(a, b)
-a, &b
-@end example
-
-A conditional expression is a valid lvalue if its type is not void and the
-true and false branches are both valid lvalues. For example, these two
-expressions are equivalent:
-
-@example
-(a ? b : c) = 5
-(a ? b = 5 : (c = 5))
-@end example
-
-A cast is a valid lvalue if its operand is an lvalue. This extension
-is deprecated. A simple
-assignment whose left-hand side is a cast works by converting the
-right-hand side first to the specified type, then to the type of the
-inner left-hand side expression. After this is stored, the value is
-converted back to the specified type to become the value of the
-assignment. Thus, if @code{a} has type @code{char *}, the following two
-expressions are equivalent:
-
-@example
-(int)a = 5
-(int)(a = (char *)(int)5)
-@end example
-
-An assignment-with-arithmetic operation such as @samp{+=} applied to a cast
-performs the arithmetic using the type resulting from the cast, and then
-continues as in the previous case. Therefore, these two expressions are
-equivalent:
-
-@example
-(int)a += 5
-(int)(a = (char *)(int) ((int)a + 5))
-@end example
-
-You cannot take the address of an lvalue cast, because the use of its
-address would not work out coherently. Suppose that @code{&(int)f} were
-permitted, where @code{f} has type @code{float}. Then the following
-statement would try to store an integer bit-pattern where a floating
-point number belongs:
-
-@example
-*&(int)f = 1;
-@end example
-
-This is quite different from what @code{(int)f = 1} would do---that
-would convert 1 to floating point and store it. Rather than cause this
-inconsistency, we think it is better to prohibit use of @samp{&} on a cast.
-
-If you really do want an @code{int *} pointer with the address of
-@code{f}, you can simply write @code{(int *)&f}.
-
@node Conditionals
@section Conditionals with Omitted Operands
@cindex conditional expressions, extensions
Therefore, the expression
-@example
+@smallexample
x ? : y
-@end example
+@end smallexample
@noindent
has the value of @code{x} if that is nonzero; otherwise, the value of
This example is perfectly equivalent to
-@example
+@smallexample
x ? x : y
-@end example
+@end smallexample
@cindex side effect in ?:
@cindex ?: side effect
last element of a structure which is really a header for a variable-length
object:
-@example
+@smallexample
struct line @{
int length;
char contents[0];
struct line *thisline = (struct line *)
malloc (sizeof (struct line) + this_length);
thisline->length = this_length;
-@end example
+@end smallexample
In ISO C90, you would have to give @code{contents} a length of 1, which
means either you waste space or complicate the argument to @code{malloc}.
I.e.@: in the following, @code{f1} is constructed as if it were declared
like @code{f2}.
-@example
+@smallexample
struct f1 @{
int x; int y[];
@} f1 = @{ 1, @{ 2, 3, 4 @} @};
struct f2 @{
struct f1 f1; int data[3];
@} f2 = @{ @{ 1 @}, @{ 2, 3, 4 @} @};
-@end example
+@end smallexample
@noindent
The convenience of this extension is that @code{f1} has the desired
non-empty initialization except when the structure is the top-level
object. For example:
-@example
+@smallexample
struct foo @{ int x; int y[]; @};
struct bar @{ struct foo z; @};
struct bar b = @{ @{ 1, @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
struct bar c = @{ @{ 1, @{ @} @} @}; // @r{Valid.}
struct foo d[1] = @{ @{ 1 @{ 2, 3, 4 @} @} @}; // @r{Invalid.}
-@end example
+@end smallexample
@node Empty Structures
@section Structures With No Members
GCC permits a C structure to have no members:
-@example
+@smallexample
struct empty @{
@};
-@end example
+@end smallexample
The structure will have size zero. In C++, empty structures are part
of the language. G++ treats empty structures as if they had a single
declaration and deallocated when the brace-level is exited. For
example:
-@example
+@smallexample
FILE *
concat_fopen (char *s1, char *s2, char *mode)
@{
strcat (str, s2);
return fopen (str, mode);
@}
-@end example
+@end smallexample
@cindex scope of a variable length array
@cindex variable-length array scope
You can also use variable-length arrays as arguments to functions:
-@example
+@smallexample
struct entry
tester (int len, char data[len][len])
@{
/* @r{@dots{}} */
@}
-@end example
+@end smallexample
The length of an array is computed once when the storage is allocated
and is remembered for the scope of the array in case you access it with
If you want to pass the array first and the length afterward, you can
use a forward declaration in the parameter list---another GNU extension.
-@example
+@smallexample
struct entry
tester (int len; char data[len][len], int len)
@{
/* @r{@dots{}} */
@}
-@end example
+@end smallexample
@cindex parameter forward declaration
The @samp{int len} before the semicolon is a @dfn{parameter forward
allowed you to give a name to the variable arguments just like any other
argument. Here is an example:
-@example
+@smallexample
#define debug(format, args...) fprintf (stderr, format, args)
-@end example
+@end smallexample
This is in all ways equivalent to the ISO C example above, but arguably
more readable and descriptive.
this invocation is invalid in ISO C, because there is no comma after
the string:
-@example
+@smallexample
debug ("A message")
-@end example
+@end smallexample
GNU CPP permits you to completely omit the variable arguments in this
way. In the above examples, the compiler would complain, though since
pointers outside C99 mode. For example,
this is valid in GNU C though not valid in C89:
-@example
+@smallexample
@group
struct foo @{int a[4];@};
return f().a[index];
@}
@end group
-@end example
+@end smallexample
@node Pointer Arith
@section Arithmetic on @code{void}- and Function-Pointers
automatic variable are not required to be constant expressions in GNU C@.
Here is an example of an initializer with run-time varying elements:
-@example
+@smallexample
foo (float f, float g)
@{
float beat_freqs[2] = @{ f-g, f+g @};
/* @r{@dots{}} */
@}
-@end example
+@end smallexample
@node Compound Literals
@section Compound Literals
Usually, the specified type is a structure. Assume that
@code{struct foo} and @code{structure} are declared as shown:
-@example
+@smallexample
struct foo @{int a; char b[2];@} structure;
-@end example
+@end smallexample
@noindent
Here is an example of constructing a @code{struct foo} with a compound literal:
-@example
+@smallexample
structure = ((struct foo) @{x + y, 'a', 0@});
-@end example
+@end smallexample
@noindent
This is equivalent to writing the following:
-@example
+@smallexample
@{
struct foo temp = @{x + y, 'a', 0@};
structure = temp;
@}
-@end example
+@end smallexample
You can also construct an array. If all the elements of the compound literal
are (made up of) simple constant expressions, suitable for use in
literal can be coerced to a pointer to its first element and used in
such an initializer, as shown here:
-@example
+@smallexample
char **foo = (char *[]) @{ "x", "y", "z" @};
-@end example
+@end smallexample
Compound literals for scalar types and union types are is
also allowed, but then the compound literal is equivalent
If the object being initialized has array type of unknown size, the size is
determined by compound literal size.
-@example
+@smallexample
static struct foo x = (struct foo) @{1, 'a', 'b'@};
static int y[] = (int []) @{1, 2, 3@};
static int z[] = (int [3]) @{1@};
-@end example
+@end smallexample
@noindent
The above lines are equivalent to the following:
-@example
+@smallexample
static struct foo x = @{1, 'a', 'b'@};
static int y[] = @{1, 2, 3@};
static int z[] = @{1, 0, 0@};
-@end example
+@end smallexample
@node Designated Inits
@section Designated Initializers
To specify an array index, write
@samp{[@var{index}] =} before the element value. For example,
-@example
+@smallexample
int a[6] = @{ [4] = 29, [2] = 15 @};
-@end example
+@end smallexample
@noindent
is equivalent to
-@example
+@smallexample
int a[6] = @{ 0, 0, 15, 0, 29, 0 @};
-@end example
+@end smallexample
@noindent
The index values must be constant expressions, even if the array being
@samp{[@var{first} ... @var{last}] = @var{value}}. This is a GNU
extension. For example,
-@example
+@smallexample
int widths[] = @{ [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 @};
-@end example
+@end smallexample
@noindent
If the value in it has side-effects, the side-effects will happen only once,
with @samp{.@var{fieldname} =} before the element value. For example,
given the following structure,
-@example
+@smallexample
struct point @{ int x, y; @};
-@end example
+@end smallexample
@noindent
the following initialization
-@example
+@smallexample
struct point p = @{ .y = yvalue, .x = xvalue @};
-@end example
+@end smallexample
@noindent
is equivalent to
-@example
+@smallexample
struct point p = @{ xvalue, yvalue @};
-@end example
+@end smallexample
Another syntax which has the same meaning, obsolete since GCC 2.5, is
@samp{@var{fieldname}:}, as shown here:
-@example
+@smallexample
struct point p = @{ y: yvalue, x: xvalue @};
-@end example
+@end smallexample
@cindex designators
The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a
syntax) when initializing a union, to specify which element of the union
should be used. For example,
-@example
+@smallexample
union foo @{ int i; double d; @};
union foo f = @{ .d = 4 @};
-@end example
+@end smallexample
@noindent
will convert 4 to a @code{double} to store it in the union using
does not have a designator applies to the next consecutive element of the
array or structure. For example,
-@example
+@smallexample
int a[6] = @{ [1] = v1, v2, [4] = v4 @};
-@end example
+@end smallexample
@noindent
is equivalent to
-@example
+@smallexample
int a[6] = @{ 0, v1, v2, 0, v4, 0 @};
-@end example
+@end smallexample
Labeling the elements of an array initializer is especially useful
when the indices are characters or belong to an @code{enum} type.
For example:
-@example
+@smallexample
int whitespace[256]
= @{ [' '] = 1, ['\t'] = 1, ['\h'] = 1,
['\f'] = 1, ['\n'] = 1, ['\r'] = 1 @};
-@end example
+@end smallexample
@cindex designator lists
You can also write a series of @samp{.@var{fieldname}} and
You can specify a range of consecutive values in a single @code{case} label,
like this:
-@example
+@smallexample
case @var{low} ... @var{high}:
-@end example
+@end smallexample
@noindent
This has the same effect as the proper number of individual @code{case}
This feature is especially useful for ranges of ASCII character codes:
-@example
+@smallexample
case 'A' ... 'Z':
-@end example
+@end smallexample
@strong{Be careful:} Write spaces around the @code{...}, for otherwise
it may be parsed wrong when you use it with integer values. For example,
write this:
-@example
+@smallexample
case 1 ... 5:
-@end example
+@end smallexample
@noindent
rather than this:
-@example
+@smallexample
case 1...5:
-@end example
+@end smallexample
@node Cast to Union
@section Cast to a Union Type
The types that may be cast to the union type are those of the members
of the union. Thus, given the following union and variables:
-@example
+@smallexample
union foo @{ int i; double d; @};
int x;
double y;
-@end example
+@end smallexample
@noindent
both @code{x} and @code{y} can be cast to type @code{union foo}.
Using the cast as the right-hand side of an assignment to a variable of
union type is equivalent to storing in a member of the union:
-@example
+@smallexample
union foo u;
/* @r{@dots{}} */
u = (union foo) x @equiv{} u.i = x
u = (union foo) y @equiv{} u.d = y
-@end example
+@end smallexample
You can also use the union cast as a function argument:
-@example
+@smallexample
void hack (union foo);
/* @r{@dots{}} */
hack ((union foo) x);
-@end example
+@end smallexample
@node Mixed Declarations
@section Mixed Declarations and Code
within compound statements. As an extension, GCC also allows this in
C89 mode. For example, you could do:
-@example
+@smallexample
int i;
/* @r{@dots{}} */
i++;
int j = i + 2;
-@end example
+@end smallexample
Each identifier is visible from where it is declared until the end of
the enclosing block.
@item malloc
@cindex @code{malloc} attribute
The @code{malloc} attribute is used to tell the compiler that a function
-may be treated as if it were the malloc function. The compiler assumes
-that calls to malloc result in pointers that cannot alias anything.
+may be treated as if any non-@code{NULL} pointer it returns cannot
+alias any other pointer valid when the function returns.
This will often improve optimization.
+Standard functions with this property include @code{malloc} and
+@code{calloc}. @code{realloc}-like functions have this property as
+long as the old pointer is never referred to (including comparing it
+to the new pointer) after the function returns a non-@code{NULL}
+value.
@item alias ("@var{target}")
@cindex @code{alias} attribute
@table @dfn
@item default
-Default visibility is the normal case for ELF. This value is
+Default visibility is the normal case for ELF. This value is
available for the visibility attribute to override other options
that may change the assumed visibility of symbols.
@cindex functions that pop the argument stack on the 386
On the Intel 386, the @code{fastcall} attribute causes the compiler to
pass the first two arguments in the registers ECX and EDX. Subsequent
-arguments are passed on the stack. The called function will pop the
+arguments are passed on the stack. The called function will pop the
arguments off the stack. If the number of arguments is variable all
arguments are pushed on the stack.
generate function entry and exit sequences suitable for use in an
interrupt handler when this attribute is present.
-Note, interrupt handlers for the H8/300, H8/300H, H8S, and SH processors can
-be specified via the @code{interrupt_handler} attribute.
+Note, interrupt handlers for the m68k, H8/300, H8/300H, H8S, and SH processors
+can be specified via the @code{interrupt_handler} attribute.
Note, on the AVR, interrupts will be enabled inside the function.
Permissible values for this parameter are: IRQ, FIQ, SWI, ABORT and UNDEF@.
@item interrupt_handler
-@cindex interrupt handler functions on the H8/300 and SH processors
-Use this attribute on the H8/300, H8/300H, H8S, and SH to indicate that the
-specified function is an interrupt handler. The compiler will generate
+@cindex interrupt handler functions on the m68k, H8/300 and SH processors
+Use this attribute on the m68k, H8/300, H8/300H, H8S, and SH to indicate that
+the specified function is an interrupt handler. The compiler will generate
function entry and exit sequences suitable for use in an interrupt
handler when this attribute is present.
@end smallexample
@item trap_exit
-Use this attribute on the SH for an @code{interrupt_handle} to return using
+Use this attribute on the SH for an @code{interrupt_handler} to return using
@code{trapa} instead of @code{rte}. This attribute expects an integer
argument specifying the trap number to be used.
@item dllimport
@cindex @code{__declspec(dllimport)}
-On Windows targets, the @code{dllimport} attribute causes the compiler
+On Microsoft Windows targets, the @code{dllimport} attribute causes the compiler
to reference a function or variable via a global pointer to a pointer
-that is set up by the Windows dll library. The pointer name is formed by
+that is set up by the Microsoft Windows dll library. The pointer name is formed by
combining @code{_imp__} and the function or variable name. The attribute
implies @code{extern} storage.
If a symbol previously declared @code{dllimport} is later defined, the
attribute is ignored in subsequent references, and a warning is emitted.
The attribute is also overridden by a subsequent declaration as
-@code{dllexport}.
+@code{dllexport}.
When applied to C++ classes, the attribute marks non-inlined
member functions and static data members as imports. However, the
On cygwin, mingw and arm-pe targets, @code{__declspec(dllimport)} is
recognized as a synonym for @code{__attribute__ ((dllimport))} for
-compatibility with other Windows compilers.
+compatibility with other Microsoft Windows compilers.
The use of the @code{dllimport} attribute on functions is not necessary,
but provides a small performance benefit by eliminating a thunk in the
dll. The use of the @code{dllimport} attribute on imported variables was
required on older versions of GNU ld, but can now be avoided by passing
the @option{--enable-auto-import} switch to ld. As with functions, using
-the attribute for a variable eliminates a thunk in the dll.
+the attribute for a variable eliminates a thunk in the dll.
One drawback to using this attribute is that a pointer to a function or
variable marked as dllimport cannot be used as a constant address. The
@item dllexport
@cindex @code{__declspec(dllexport)}
-On Windows targets the @code{dllexport} attribute causes the compiler to
+On Microsoft Windows targets the @code{dllexport} attribute causes the compiler to
provide a global pointer to a pointer in a dll, so that it can be
referenced with the @code{dllimport} attribute. The pointer name is
formed by combining @code{_imp__} and the function or variable name.
On cygwin, mingw and arm-pe targets, @code{__declspec(dllexport)} is
recognized as a synonym for @code{__attribute__ ((dllexport))} for
-compatibility with other Windows compilers.
+compatibility with other Microsoft Windows compilers.
Alternative methods for including the symbol in the dll's export table
are to use a .def file with an @code{EXPORTS} section or, with GNU ld,
GNU C extends ISO C to allow a function prototype to override a later
old-style non-prototype definition. Consider the following example:
-@example
+@smallexample
/* @r{Use prototypes unless the compiler is old-fashioned.} */
#ifdef __STDC__
#define P(x) x
@{
return x == 0;
@}
-@end example
+@end smallexample
Suppose the type @code{uid_t} happens to be @code{short}. ISO C does
not allow this example, because subword arguments in old-style
latter type before promotion. Thus in GNU C the above example is
equivalent to the following:
-@example
+@smallexample
int isroot (uid_t);
int
@{
return x == 0;
@}
-@end example
+@end smallexample
@noindent
GNU C++ does not support old-style function definitions, so this
extension (@pxref{Variable Attributes}). For example, after this
declaration:
-@example
+@smallexample
struct foo @{ int x; char y; @} foo1;
-@end example
+@end smallexample
@noindent
the value of @code{__alignof__ (foo1.y)} is 1, even though its actual
``common'' storage. The @code{nocommon} attribute requests the
opposite -- to allocate space for it directly.
-These attributes override the default chosen by the
+These attributes override the default chosen by the
@option{-fno-common} and @option{-fcommon} flags respectively.
@item deprecated
Here is a structure in which the field @code{x} is packed, so that it
immediately follows @code{a}:
-@example
+@smallexample
struct foo
@{
char a;
int x[2] __attribute__ ((packed));
@};
-@end example
+@end smallexample
@item section ("@var{section-name}")
@cindex @code{section} variable attribute
@item shared
@cindex @code{shared} variable attribute
-On Windows, in addition to putting variable definitions in a named
+On Microsoft Windows, in addition to putting variable definitions in a named
section, the section can also be shared among all running copies of an
executable or DLL@. For example, this small program defines shared data
by putting it in a named section @code{shared} and marking the section
attribute with a fully initialized global definition because of the way
linkers work. See @code{section} attribute for more information.
-The @code{shared} attribute is only available on Windows@.
+The @code{shared} attribute is only available on Microsoft Windows@.
@item tls_model ("@var{tls_model}")
@cindex @code{tls_model} attribute
(either via function call or as data in a file), it may be necessary to access
either format.
-Currently @option{-m[no-]ms-bitfields} is provided for the Windows X86
+Currently @option{-m[no-]ms-bitfields} is provided for the Microsoft Windows X86
compilers to match the native Microsoft compiler.
@end table
arguments to be passed, using the @code{int *} calling convention.
The program can call @code{wait} with arguments of either type:
-@example
+@smallexample
int w1 () @{ int w; return wait (&w); @}
int w2 () @{ union wait w; return wait (&w); @}
-@end example
+@end smallexample
With this interface, @code{wait}'s implementation might look like this:
-@example
+@smallexample
pid_t wait (wait_status_ptr_t p)
@{
return waitpid (-1, p.__ip, 0);
@}
-@end example
+@end smallexample
@item unused
When attached to a type (including a @code{union} or a @code{struct}),
(either via function call or as data in a file), it may be necessary to access
either format.
-Currently @option{-m[no-]ms-bitfields} is provided for the Windows X86
+Currently @option{-m[no-]ms-bitfields} is provided for the Microsoft Windows X86
compilers to match the native Microsoft compiler.
@end table
To declare a function inline, use the @code{inline} keyword in its
declaration, like this:
-@example
+@smallexample
inline int
inc (int *a)
@{
(*a)++;
@}
-@end example
+@end smallexample
(If you are writing a header file to be included in ISO C programs, write
@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.)
GCC does not inline any functions when not optimizing unless you specify
the @samp{always_inline} attribute for the function, like this:
-@example
+@smallexample
/* Prototype. */
inline void foo (const char) __attribute__((always_inline));
-@end example
+@end smallexample
@node Extended Asm
@section Assembler Instructions with C Expression Operands
For example, here is how to use the 68881's @code{fsinx} instruction:
-@example
+@smallexample
asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
-@end example
+@end smallexample
@noindent
Here @code{angle} is the C expression for the input operand while
followed by the operand number. Using named operands the above example
could look like:
-@example
+@smallexample
asm ("fsinx %[angle],%[output]"
: [output] "=f" (result)
: [angle] "f" (angle));
-@end example
+@end smallexample
@noindent
Note that the symbolic operand names have no relation whatsoever to
the values in these operands before the instruction are dead and need
not be generated. Extended asm supports input-output or read-write
operands. Use the constraint character @samp{+} to indicate such an
-operand and list it with the output operands.
-
-When the constraints for the read-write operand (or the operand in which
-only some of the bits are to be changed) allows a register, you may, as
-an alternative, logically split its function into two separate operands,
-one input operand and one write-only output operand. The connection
-between them is expressed by constraints which say they need to be in
-the same location when the instruction executes. You can use the same C
-expression for both operands, or different expressions. For example,
-here we write the (fictitious) @samp{combine} instruction with
-@code{bar} as its read-only source operand and @code{foo} as its
-read-write destination:
+operand and list it with the output operands. You should only use
+read-write operands when the constraints for the operand (or the
+operand in which only some of the bits are to be changed) allow a
+register.
+
+You may, as an alternative, logically split its function into two
+separate operands, one input operand and one write-only output
+operand. The connection between them is expressed by constraints
+which say they need to be in the same location when the instruction
+executes. You can use the same C expression for both operands, or
+different expressions. For example, here we write the (fictitious)
+@samp{combine} instruction with @code{bar} as its read-only source
+operand and @code{foo} as its read-write destination:
-@example
+@smallexample
asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
-@end example
+@end smallexample
@noindent
The constraint @samp{"0"} for operand 1 says that it must occupy the
same place in the generated assembler code. The following would not
work reliably:
-@example
+@smallexample
asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
-@end example
+@end smallexample
Various optimizations or reloading could cause operands 0 and 1 to be in
different registers; GCC knows no reason not to do so. For example, the
As of GCC version 3.1, one may write @code{[@var{name}]} instead of
the operand number for a matching constraint. For example:
-@example
+@smallexample
asm ("cmoveq %1,%2,%[result]"
: [result] "=r"(result)
: "r" (test), "r"(new), "[result]"(old));
-@end example
+@end smallexample
Some instructions clobber specific hard registers. To describe this,
write a third colon after the input operands, followed by the names of
the clobbered hard registers (given as strings). Here is a realistic
example for the VAX:
-@example
+@smallexample
asm volatile ("movc3 %0,%1,%2"
: /* no outputs */
: "g" (from), "g" (to), "g" (count)
: "r0", "r1", "r2", "r3", "r4", "r5");
-@end example
+@end smallexample
You may not write a clobber description in a way that overlaps with an
input or output operand. For example, you may not have an operand
condition code is handled differently, and specifying @samp{cc} has no
effect. But it is valid no matter what the machine.
-If your assembler instruction modifies memory in an unpredictable
+If your assembler instructions access memory in an unpredictable
fashion, add @samp{memory} to the list of clobbered registers. This
-will cause GCC to not keep memory values cached in registers across
-the assembler instruction. You will also want to add the
-@code{volatile} keyword if the memory affected is not listed in the
-inputs or outputs of the @code{asm}, as the @samp{memory} clobber does
-not count as a side-effect of the @code{asm}.
+will cause GCC to not keep memory values cached in registers across the
+assembler instruction and not optimize stores or loads to that memory.
+You will also want to add the @code{volatile} keyword if the memory
+affected is not listed in the inputs or outputs of the @code{asm}, as
+the @samp{memory} clobber does not count as a side-effect of the
+@code{asm}. If you know how large the accessed memory is, you can add
+it as input or output but if this is not known, you should add
+@samp{memory}. As an example, if you access ten bytes of a string, you
+can use a memory input like:
+
+@example
+@{"m"( (@{ struct @{ char x[10]; @} *p = (void *)ptr ; *p; @}) )@}.
+@end example
+
+Note that in the following example the memory input is necessary,
+otherwise GCC might optimize the store to @code{x} away:
+@example
+int foo ()
+@{
+ int x = 42;
+ int *y = &x;
+ int result;
+ asm ("magic stuff accessing an 'int' pointed to by '%1'"
+ "=&d" (r) : "a" (y), "m" (*y));
+ return result;
+@}
+@end example
You can put multiple assembler instructions together in a single
@code{asm} template, separated by the characters normally used in assembly
is an example of multiple instructions in a template; it assumes the
subroutine @code{_foo} accepts arguments in registers 9 and 10:
-@example
+@smallexample
asm ("movl %0,r9\n\tmovl %1,r10\n\tcall _foo"
: /* no outputs */
: "g" (from), "g" (to)
: "r9", "r10");
-@end example
+@end smallexample
Unless an output operand has the @samp{&} constraint modifier, GCC
may allocate it in the same register as an unrelated input operand, on
instruction, you must include a branch and a label in the @code{asm}
construct, as follows:
-@example
+@smallexample
asm ("clr %0\n\tfrob %1\n\tbeq 0f\n\tmov #1,%0\n0:"
: "g" (result)
: "g" (input));
-@end example
+@end smallexample
@noindent
This assumes your assembler supports local labels, as the GNU assembler
Usually the most convenient way to use these @code{asm} instructions is to
encapsulate them in macros that look like functions. For example,
-@example
+@smallexample
#define sin(x) \
(@{ double __value, __arg = (x); \
asm ("fsinx %1,%0": "=f" (__value): "f" (__arg)); \
__value; @})
-@end example
+@end smallexample
@noindent
Here the variable @code{__arg} is used to make sure that the instruction
significantly, or combined, by writing the keyword @code{volatile} after
the @code{asm}. For example:
-@example
+@smallexample
#define get_and_set_priority(new) \
(@{ int __old; \
asm volatile ("get_and_set_priority %0, %1" \
: "=g" (__old) : "g" (new)); \
__old; @})
-@end example
+@end smallexample
@noindent
If you write an @code{asm} instruction with no outputs, GCC will know
instruction.) In addition, GCC will not reschedule instructions
across a volatile @code{asm} instruction. For example:
-@example
+@smallexample
*(volatile int *)addr = foo;
asm volatile ("eieio" : : );
-@end example
+@end smallexample
@noindent
Assume @code{addr} contains the address of a memory mapped device
It is possible that if an input dies in an insn, reload might
use the input reg for an output reload. Consider this example:
-@example
+@smallexample
asm ("foo" : "=t" (a) : "f" (b));
-@end example
+@end smallexample
This asm says that input B is not popped by the asm, and that
the asm pushes a result onto the reg-stack, i.e., the stack is one
The asm above would be written as
-@example
+@smallexample
asm ("foo" : "=&t" (a) : "f" (b));
-@end example
+@end smallexample
@item
Some operands need to be in particular places on the stack. All
Here are a couple of reasonable asms to want to write. This asm
takes one input, which is internally popped, and produces two outputs.
-@example
+@smallexample
asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
-@end example
+@end smallexample
This asm takes two inputs, which are popped by the @code{fyl2xp1} opcode,
and replaces them with one output. The user must code the @code{st(1)}
clobber for reg-stack.c to know that @code{fyl2xp1} pops both inputs.
-@example
+@smallexample
asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
-@end example
+@end smallexample
@include md.texi
function or variable by writing the @code{asm} (or @code{__asm__})
keyword after the declarator as follows:
-@example
+@smallexample
int foo asm ("myfoo") = 2;
-@end example
+@end smallexample
@noindent
This specifies that the name to be used for the variable @code{foo} in
you can get the same effect by writing a declaration for the function
before its definition and putting @code{asm} there, like this:
-@example
+@smallexample
extern func () asm ("FUNC");
func (x, y)
int x, y;
/* @r{@dots{}} */
-@end example
+@end smallexample
It is up to you to make sure that the assembler names you choose do not
conflict with any other assembler symbols. Also, you must not use a
You can define a global register variable in GNU C like this:
-@example
+@smallexample
register int *foo asm ("a5");
-@end example
+@end smallexample
@noindent
Here @code{a5} is the name of the register which should be used. Choose a
You can define a local register variable with a specified register
like this:
-@example
+@smallexample
register int *foo asm ("a5");
-@end example
+@end smallexample
@noindent
Here @code{a5} is the name of the register which should be used. Note
compile with another compiler, you can define the alternate keywords as
macros to replace them with the customary keywords. It looks like this:
-@example
+@smallexample
#ifndef __GNUC__
#define __asm__ asm
#endif
-@end example
+@end smallexample
@findex __extension__
@opindex pedantic
The first step in using these extensions is to provide the necessary data
types. This should be done using an appropriate @code{typedef}:
-@example
+@smallexample
typedef int v4si __attribute__ ((mode(V4SI)));
-@end example
+@end smallexample
The base type @code{int} is effectively ignored by the compiler, the
actual properties of the new type @code{v4si} are defined by the
produce code that uses 4 @code{SIs}.
The types defined in this manner can be used with a subset of normal C
-operations. Currently, gcc will allow using the following operators on
-these types: @code{+, -, *, /, unary minus}@.
+operations. Currently, gcc will allow using the following operators
+on these types: @code{+, -, *, /, unary minus, ^, |, &, ~}@.
The operations behave like C++ @code{valarrays}. Addition is defined as
the addition of the corresponding elements of the operands. For
added to the corresponding 4 elements in @var{b} and the resulting
vector will be stored in @var{c}.
-@example
+@smallexample
typedef int v4si __attribute__ ((mode(V4SI)));
v4si a, b, c;
c = a + b;
-@end example
+@end smallexample
-Subtraction, multiplication, and division operate in a similar manner.
-Likewise, the result of using the unary minus operator on a vector type
-is a vector whose elements are the negative value of the corresponding
+Subtraction, multiplication, division, and the logical operations
+operate in a similar manner. Likewise, the result of using the unary
+minus or complement operators on a vector type is a vector whose
+elements are the negative or complemented values of the corresponding
elements in the operand.
You can declare variables and use them in function calls and returns, as
example, a function to add two vectors and multiply the result by a
third could look like this:
-@example
+@smallexample
v4si f (v4si a, v4si b, v4si c)
@{
v4si tmp = __builtin_addv4si (a, b);
return __builtin_mulv4si (tmp, c);
@}
-@end example
+@end smallexample
@node Other Builtins
@section Other built-in functions provided by GCC
@findex scalbn
@findex scalbnf
@findex scanfnl
+@findex signbit
+@findex signbitf
+@findex signbitl
@findex significand
@findex significandf
@findex significandl
@code{j1}, @code{jnf}, @code{jnl}, @code{jn}, @code{mempcpy},
@code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked},
@code{rindex}, @code{scalbf}, @code{scalbl}, @code{scalb},
+@code{signbit}, @code{signbitf}, @code{signbitl},
@code{significandf}, @code{significandl}, @code{significand},
@code{sincosf}, @code{sincosl}, @code{sincos}, @code{stpcpy},
@code{strdup}, @code{strfmon}, @code{y0f}, @code{y0l}, @code{y0},
@code{short **}. Furthermore, two types that are typedefed are
considered compatible if their underlying types are compatible.
-An @code{enum} type is considered to be compatible with another
-@code{enum} type. For example, @code{enum @{foo, bar@}} is similar to
+An @code{enum} type is not considered to be compatible with another
+@code{enum} type even if both are compatible with the same integer
+type; this is what the C standard specifies.
+For example, @code{enum @{foo, bar@}} is not similar to
@code{enum @{hot, dog@}}.
You would typically use this function in code whose execution varies
is parsed as by @code{strtol}; that is, the base is recognized by
leading @samp{0} or @samp{0x} prefixes. The number parsed is placed
in the significand such that the least significant bit of the number
-is at the least significant bit of the significand. The number is
+is at the least significant bit of the significand. The number is
truncated to fit the significand field provided. The significand is
forced to be a quiet NaN.
@end deftypefn
@deftypefn {Built-in Function} double __builtin_nans (const char *str)
-Similar to @code{__builtin_nan}, except the significand is forced
+Similar to @code{__builtin_nan}, except the significand is forced
to be a signaling NaN. The @code{nans} function is proposed by
@uref{http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n965.htm,,WG14 N965}.
@end deftypefn
The following built-in functions are always available. They
all generate the machine instruction that is part of the name.
-@example
+@smallexample
long __builtin_alpha_implver (void)
long __builtin_alpha_rpcc (void)
long __builtin_alpha_amask (long)
long __builtin_alpha_umulh (long, long)
long __builtin_alpha_zap (long, long)
long __builtin_alpha_zapnot (long, long)
-@end example
+@end smallexample
The following built-in functions are always with @option{-mmax}
or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{pca56} or
later. They all generate the machine instruction that is part
of the name.
-@example
+@smallexample
long __builtin_alpha_pklb (long)
long __builtin_alpha_pkwb (long)
long __builtin_alpha_unpkbl (long)
long __builtin_alpha_maxuw4 (long, long)
long __builtin_alpha_maxsw4 (long, long)
long __builtin_alpha_perr (long, long)
-@end example
+@end smallexample
The following built-in functions are always with @option{-mcix}
or @option{-mcpu=@var{cpu}} where @var{cpu} is @code{ev67} or
later. They all generate the machine instruction that is part
of the name.
-@example
+@smallexample
long __builtin_alpha_cttz (long)
long __builtin_alpha_ctlz (long)
long __builtin_alpha_ctpop (long)
-@end example
+@end smallexample
The following builtins are available on systems that use the OSF/1
PALcode. Normally they invoke the @code{rduniq} and @code{wruniq}
PAL calls, but when invoked with @option{-mtls-kernel}, they invoke
@code{rdval} and @code{wrval}.
-@example
+@smallexample
void *__builtin_thread_pointer (void)
void __builtin_set_thread_pointer (void *)
-@end example
+@end smallexample
@node ARM Built-in Functions
@subsection ARM Built-in Functions
These built-in functions are available for the ARM family of
processors, when the @option{-mcpu=iwmmxt} switch is used:
-@example
+@smallexample
typedef int __v2si __attribute__ ((__mode__ (__V2SI__)))
v2si __builtin_arm_waddw (v2si, v2si)
v2si __builtin_arm_wsubwss (v2si, v2si)
v2si __builtin_arm_wsraw (v2si, v2si)
v2si __builtin_arm_wsrad (v2si, v2si)
-@end example
+@end smallexample
@node X86 Built-in Functions
@subsection X86 Built-in Functions
The following built-in functions are made available by @option{-mmmx}.
All of them generate the machine instruction that is part of the name.
-@example
+@smallexample
v8qi __builtin_ia32_paddb (v8qi, v8qi)
v4hi __builtin_ia32_paddw (v4hi, v4hi)
v2si __builtin_ia32_paddd (v2si, v2si)
v8qi __builtin_ia32_packsswb (v4hi, v4hi)
v4hi __builtin_ia32_packssdw (v2si, v2si)
v8qi __builtin_ia32_packuswb (v4hi, v4hi)
-@end example
+@end smallexample
The following built-in functions are made available either with
@option{-msse}, or with a combination of @option{-m3dnow} and
@option{-march=athlon}. All of them generate the machine
instruction that is part of the name.
-@example
+@smallexample
v4hi __builtin_ia32_pmulhuw (v4hi, v4hi)
v8qi __builtin_ia32_pavgb (v8qi, v8qi)
v4hi __builtin_ia32_pavgw (v4hi, v4hi)
void __builtin_ia32_maskmovq (v8qi, v8qi, char *)
void __builtin_ia32_movntq (di *, di)
void __builtin_ia32_sfence (void)
-@end example
+@end smallexample
The following built-in functions are available when @option{-msse} is used.
All of them generate the machine instruction that is part of the name.
-@example
+@smallexample
int __builtin_ia32_comieq (v4sf, v4sf)
int __builtin_ia32_comineq (v4sf, v4sf)
int __builtin_ia32_comilt (v4sf, v4sf)
v4sf __builtin_ia32_shufps (v4sf, v4sf, int)
void __builtin_ia32_movntps (float *, v4sf)
int __builtin_ia32_movmskps (v4sf)
-@end example
+@end smallexample
The following built-in functions are available when @option{-msse} is used.
The following built-in functions are available when @option{-mpni} is used.
All of them generate the machine instruction that is part of the name.
-@example
+@smallexample
v2df __builtin_ia32_addsubpd (v2df, v2df)
v2df __builtin_ia32_addsubps (v2df, v2df)
v2df __builtin_ia32_haddpd (v2df, v2df)
v4sf __builtin_ia32_movshdup (v4sf)
v4sf __builtin_ia32_movsldup (v4sf)
void __builtin_ia32_mwait (unsigned int, unsigned int)
-@end example
+@end smallexample
The following built-in functions are available when @option{-mpni} is used.
The following built-in functions are available when @option{-m3dnow} is used.
All of them generate the machine instruction that is part of the name.
-@example
+@smallexample
void __builtin_ia32_femms (void)
v8qi __builtin_ia32_pavgusb (v8qi, v8qi)
v2si __builtin_ia32_pf2id (v2sf)
v2sf __builtin_ia32_pfsubr (v2sf, v2sf)
v2sf __builtin_ia32_pi2fd (v2si)
v4hi __builtin_ia32_pmulhrw (v4hi, v4hi)
-@end example
+@end smallexample
The following built-in functions are available when both @option{-m3dnow}
and @option{-march=athlon} are used. All of them generate the machine
instruction that is part of the name.
-@example
+@smallexample
v2si __builtin_ia32_pf2iw (v2sf)
v2sf __builtin_ia32_pfnacc (v2sf, v2sf)
v2sf __builtin_ia32_pfpnacc (v2sf, v2sf)
v2sf __builtin_ia32_pi2fw (v2si)
v2sf __builtin_ia32_pswapdsf (v2sf)
v2si __builtin_ia32_pswapdsi (v2si)
-@end example
+@end smallexample
@node PowerPC AltiVec Built-in Functions
@subsection PowerPC AltiVec Built-in Functions
a structure or union that contains, as fields, structures and unions
without names. For example:
-@example
+@smallexample
struct @{
int a;
union @{
@};
int d;
@} foo;
-@end example
+@end smallexample
In this example, the user would be able to access members of the unnamed
union with code like @samp{foo.b}. Note that only unnamed structs and
You must never create such structures that cause ambiguous field definitions.
For example, this structure:
-@example
+@smallexample
struct @{
int a;
struct @{
int a;
@};
@} foo;
-@end example
+@end smallexample
It is ambiguous which @code{a} is being referred to with @samp{foo.a}.
Such constructs are not supported and must be avoided. In the future,
At the user level, the extension is visible with a new storage
class keyword: @code{__thread}. For example:
-@example
+@smallexample
__thread int i;
extern __thread struct state s;
static __thread char *p;
-@end example
+@end smallexample
The @code{__thread} specifier may be used alone, with the @code{extern}
or @code{static} specifiers, but with no other storage class specifier.
* Bound member functions:: You can extract a function pointer to the
method denoted by a @samp{->*} or @samp{.*} expression.
* C++ Attributes:: Variable, function, and type attributes for C++ only.
+* Strong Using:: Strong using-directives for namespace composition.
+* Offsetof:: Special syntax for implementing @code{offsetof}.
* Java Exceptions:: Tweaking exception handling to work with Java.
* Deprecated Features:: Things will disappear from g++.
* Backwards Compatibility:: Compatibilities with earlier definitions of C++.
use a macro to return the minimum of two things in C++, as in the
following example.
-@example
+@smallexample
#define MIN(X,Y) ((X) < (Y) ? : (X) : (Y))
-@end example
+@end smallexample
@noindent
You might then use @w{@samp{int min = MIN (i, j);}} to set @var{min} to
In most expressions, it is intuitively obvious what is a read and what is
a write. For instance
-@example
+@smallexample
volatile int *dst = @var{somevalue};
volatile int *src = @var{someothervalue};
*dst = *src;
-@end example
+@end smallexample
@noindent
will cause a read of the volatile object pointed to by @var{src} and stores the
Less obvious expressions are where something which looks like an access
is used in a void context. An example would be,
-@example
+@smallexample
volatile int *src = @var{somevalue};
*src;
-@end example
+@end smallexample
With C, such expressions are rvalues, and as rvalues cause a read of
the object, GCC interprets this as a read of the volatile being pointed
of the object. When the object has incomplete type, G++ issues a
warning.
-@example
+@smallexample
struct S;
struct T @{int m;@};
volatile S *ptr1 = @var{somevalue};
volatile T *ptr2 = @var{somevalue};
*ptr1;
*ptr2;
-@end example
+@end smallexample
In this example, a warning is issued for @code{*ptr1}, and @code{*ptr2}
causes a read of the object pointed to. If you wish to force an error on
references, which indicate that the reference is not aliased in the local
context.
-@example
+@smallexample
void fn (int *__restrict__ rptr, int &__restrict__ rref)
@{
/* @r{@dots{}} */
@}
-@end example
+@end smallexample
@noindent
In the body of @code{fn}, @var{rptr} points to an unaliased integer and
You may also specify whether a member function's @var{this} pointer is
unaliased by using @code{__restrict__} as a member function qualifier.
-@example
+@smallexample
void T::fn () __restrict__
@{
/* @r{@dots{}} */
@}
-@end example
+@end smallexample
@noindent
Within the body of @code{T::fn}, @var{this} will have the effective
@end table
When used with GNU ld version 2.8 or later on an ELF system such as
-Linux/GNU or Solaris 2, or on Microsoft Windows, duplicate copies of
+GNU/Linux or Solaris 2, or on Microsoft Windows, duplicate copies of
these constructs will be discarded at link time. This is known as
COMDAT support.
@end table
When used with GNU ld version 2.8 or later on an ELF system such as
-Linux/GNU or Solaris 2, or on Microsoft Windows, g++ supports the
+GNU/Linux or Solaris 2, or on Microsoft Windows, g++ supports the
Borland model. On other systems, g++ implements neither automatic
model.
instantiations you need into one big file; or you can create small files
like
-@example
+@smallexample
#include "Foo.h"
#include "Foo.cc"
template class Foo<int>;
template ostream& operator <<
(ostream&, const Foo<int>&);
-@end example
+@end smallexample
for each of the instances you need, and create a template instantiation
library from those.
members of a template class, without the support data or member
functions (with (@code{static}):
-@example
+@smallexample
extern template int max (int, int);
inline template class Foo<int>;
static template class Foo<int>;
-@end example
+@end smallexample
@item
Do nothing. Pretend g++ does implement automatic instantiation
The syntax for this extension is
-@example
+@smallexample
extern A a;
extern int (A::*fp)();
typedef int (*fptr)(A *);
fptr p = (fptr)(a.*fp);
-@end example
+@end smallexample
For PMF constants (i.e.@: expressions of the form @samp{&Klasse::Member}),
no object is needed to obtain the address of the function. They can be
converted to function pointers directly:
-@example
+@smallexample
fptr p1 = (fptr)(&A::foo);
-@end example
+@end smallexample
@opindex Wno-pmf-conversions
You must specify @option{-Wno-pmf-conversions} to use this extension.
@end table
+See also @xref{Strong Using}.
+
+@node Strong Using
+@section Strong Using
+
+A using-directive with @code{__attribute ((strong))} is stronger
+than a normal using-directive in two ways:
+
+@itemize @bullet
+@item
+Templates from the used namespace can be specialized as though they were members of the using namespace.
+
+@item
+The using namespace is considered an associated namespace of all
+templates in the used namespace for purposes of argument-dependent
+name lookup.
+@end itemize
+
+This is useful for composing a namespace transparently from
+implementation namespaces. For example:
+
+@smallexample
+namespace std @{
+ namespace debug @{
+ template <class T> struct A @{ @};
+ @}
+ using namespace debug __attribute ((__strong__));
+ template <> struct A<int> @{ @}; // ok to specialize
+
+ template <class T> void f (A<T>);
+@}
+
+int main()
+@{
+ f (std::A<float>()); // lookup finds std::f
+ f (std::A<int>());
+@}
+@end smallexample
+
+@node Offsetof
+@section Offsetof
+
+G++ uses a syntactic extension to implement the @code{offsetof} macro.
+
+In particular:
+
+@smallexample
+ __offsetof__ (expression)
+@end smallexample
+
+is equivalent to the parenthesized expression, except that the
+expression is considered an integral constant expression even if it
+contains certain operators that are not normally permitted in an
+integral constant expression. Users should never use
+@code{__offsetof__} directly; the only valid use of
+@code{__offsetof__} is to implement the @code{offsetof} macro in
+@code{<stddef.h>}.
+
@node Java Exceptions
@section Java Exceptions