Commit 348846ff by Martin Sebor Committed by Martin Sebor

extend.texi (Function Attributes): Clarify C++ aspects.


gcc/ChangeLog:

	* doc/extend.texi (Function Attributes): Clarify C++ aspects.
	(Variable Attributes): Same.
	(Type Attributes): Same.

From-SVN: r267064
parent c46eb979
2018-12-12 Martin Sebor <msebor@redhat.com>
* doc/extend.texi (Function Attributes): Clarify C++ aspects.
(Variable Attributes): Same.
(Type Attributes): Same.
2018-12-12 Olivier Hainque <hainque@adacore.com> 2018-12-12 Olivier Hainque <hainque@adacore.com>
* config/aarch64/aarch64.c (aarch64_override_options): Once arch, * config/aarch64/aarch64.c (aarch64_override_options): Once arch,
...@@ -2332,30 +2332,46 @@ the enclosing block. ...@@ -2332,30 +2332,46 @@ the enclosing block.
@cindex @code{volatile} applied to function @cindex @code{volatile} applied to function
@cindex @code{const} applied to function @cindex @code{const} applied to function
In GNU C, you can use function attributes to declare certain things In GNU C and C++, you can use function attributes to specify certain
about functions called in your program which help the compiler function properties that may help the compiler optimize calls or
optimize calls and check your code more carefully. For example, you check code more carefully for correctness. For example, you
can use attributes to declare that a function never returns can use attributes to specify that a function never returns
(@code{noreturn}), returns a value depending only on its arguments (@code{noreturn}), returns a value depending only on the values of
(@code{pure}), or has @code{printf}-style arguments (@code{format}). its arguments (@code{const}), or has @code{printf}-style arguments
(@code{format}).
You can also use attributes to control memory placement, code You can also use attributes to control memory placement, code
generation options or call/return conventions within the function generation options or call/return conventions within the function
being annotated. Many of these attributes are target-specific. For being annotated. Many of these attributes are target-specific. For
example, many targets support attributes for defining interrupt example, many targets support attributes for defining interrupt
handler functions, which typically must follow special register usage handler functions, which typically must follow special register usage
and return conventions. and return conventions. Such attributes are described in the subsection
for each target. However, a considerable number of attributes are
supported by most, if not all targets. Those are described in
the @ref{Common Function Attributes} section.
Function attributes are introduced by the @code{__attribute__} keyword Function attributes are introduced by the @code{__attribute__} keyword
on a declaration, followed by an attribute specification inside double in the declaration of a function, followed by an attribute specification
parentheses. You can specify multiple attributes in a declaration by enclosed in double parentheses. You can specify multiple attributes in
separating them by commas within the double parentheses or by a declaration by separating them by commas within the double parentheses
immediately following an attribute declaration with another attribute or by immediately following one attribute specification with another.
declaration. @xref{Attribute Syntax}, for the exact rules on attribute @xref{Attribute Syntax}, for the exact rules on attribute syntax and
syntax and placement. Compatible attribute specifications on distinct placement. Compatible attribute specifications on distinct declarations
declarations of the same function are merged. An attribute specification of the same function are merged. An attribute specification that is not
that is not compatible with attributes already applied to a declaration compatible with attributes already applied to a declaration of the same
of the same function is ignored with a warning. function is ignored with a warning.
Some function attributes take one or more arguments that refer to
the function's parameters by their positions within the function parameter
list. Such attribute arguments are referred to as @dfn{positional arguments}.
Unless specified otherwise, positional arguments that specify properties
of parameters with pointer types can also specify the same properties of
the implicit C++ @code{this} argument in non-static member functions, and
of parameters of reference to a pointer type. For ordinary functions,
position one refers to the first parameter on the list. In C++ non-static
member functions, position one refers to the implicit @code{this} pointer.
The same restrictions and effects apply to function attributes used with
ordinary functions or C++ member functions.
GCC also supports attributes on GCC also supports attributes on
variable declarations (@pxref{Variable Attributes}), variable declarations (@pxref{Variable Attributes}),
...@@ -6127,13 +6143,13 @@ when this attribute is present. ...@@ -6127,13 +6143,13 @@ when this attribute is present.
@cindex attribute of variables @cindex attribute of variables
@cindex variable attributes @cindex variable attributes
The keyword @code{__attribute__} allows you to specify special The keyword @code{__attribute__} allows you to specify special properties
attributes of variables or structure fields. This keyword is followed of variables, function parameters, or structure, union, and, in C++, class
by an attribute specification inside double parentheses. Some members. This @code{__attribute__} keyword is followed by an attribute
attributes are currently defined generically for variables. specification enclosed in double parentheses. Some attributes are currently
Other attributes are defined for variables on particular target defined generically for variables. Other attributes are defined for
systems. Other attributes are available for functions variables on particular target systems. Other attributes are available
(@pxref{Function Attributes}), labels (@pxref{Label Attributes}), for functions (@pxref{Function Attributes}), labels (@pxref{Label Attributes}),
enumerators (@pxref{Enumerator Attributes}), statements enumerators (@pxref{Enumerator Attributes}), statements
(@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}). (@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}).
Other front ends might define more attributes Other front ends might define more attributes
...@@ -7086,17 +7102,21 @@ placed in either the @code{.bss_below100} section or the ...@@ -7086,17 +7102,21 @@ placed in either the @code{.bss_below100} section or the
@cindex attribute of types @cindex attribute of types
@cindex type attributes @cindex type attributes
The keyword @code{__attribute__} allows you to specify special The keyword @code{__attribute__} allows you to specify various special
attributes of types. Some type attributes apply only to @code{struct} properties of types. Some type attributes apply only to structure and
and @code{union} types, while others can apply to any type defined union types, and in C++, also class types, while others can apply to
via a @code{typedef} declaration. Other attributes are defined for any type defined via a @code{typedef} declaration. Unless otherwise
functions (@pxref{Function Attributes}), labels (@pxref{Label specified, the same restrictions and effects apply to attributes regardless
Attributes}), enumerators (@pxref{Enumerator Attributes}), of whether a type is a trivial structure or a C++ class with user-defined
statements (@pxref{Statement Attributes}), and for constructors, destructors, or a copy assignment.
variables (@pxref{Variable Attributes}).
Other attributes are defined for functions (@pxref{Function Attributes}),
labels (@pxref{Label Attributes}), enumerators (@pxref{Enumerator
Attributes}), statements (@pxref{Statement Attributes}), and for variables
(@pxref{Variable Attributes}).
The @code{__attribute__} keyword is followed by an attribute specification The @code{__attribute__} keyword is followed by an attribute specification
inside double parentheses. enclosed in double parentheses.
You may specify type attributes in an enum, struct or union type You may specify type attributes in an enum, struct or union type
declaration or definition by placing them immediately after the declaration or definition by placing them immediately after the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment