summaryrefslogtreecommitdiffstats
path: root/contrib/gcc/doc/extend.texi
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/gcc/doc/extend.texi')
-rw-r--r--contrib/gcc/doc/extend.texi115
1 files changed, 53 insertions, 62 deletions
diff --git a/contrib/gcc/doc/extend.texi b/contrib/gcc/doc/extend.texi
index 0ba7c29..7d3c010 100644
--- a/contrib/gcc/doc/extend.texi
+++ b/contrib/gcc/doc/extend.texi
@@ -3829,66 +3829,54 @@ These attributes mainly are intended to support the @code{__vector},
@cindex open coding
@cindex macros, inline alternative
-By declaring a function @code{inline}, you can direct GCC to
+By declaring a function inline, you can direct GCC to make
+calls to that function faster. One way GCC can achieve this is to
integrate that function's code into the code for its callers. This
makes execution faster by eliminating the function-call overhead; in
-addition, if any of the actual argument values are constant, their known
-values may permit simplifications at compile time so that not all of the
-inline function's code needs to be included. The effect on code size is
-less predictable; object code may be larger or smaller with function
-inlining, depending on the particular case. Inlining of functions is an
-optimization and it really ``works'' only in optimizing compilation. If
-you don't use @option{-O}, no function is really inline.
-
-Inline functions are included in the ISO C99 standard, but there are
-currently substantial differences between what GCC implements and what
-the ISO C99 standard requires. GCC will fully support C99 inline
-functions in version 4.3. The traditional GCC handling of inline
-functions will still be available with @option{-std=gnu89},
-@option{-fgnu89-inline} or when @code{gnu_inline} attribute is present
-on all inline declarations. The preprocessor macros
-@code{__GNUC_GNU_INLINE__} and @code{__GNUC_STDC_INLINE__} may be used
-to determine the handling of @code{inline} during a particular
-compilation (@pxref{Common Predefined Macros,,,cpp,The C
-Preprocessor}).
+addition, if any of the actual argument values are constant, their
+known values may permit simplifications at compile time so that not
+all of the inline function's code needs to be included. The effect on
+code size is less predictable; object code may be larger or smaller
+with function inlining, depending on the particular case. You can
+also direct GCC to try to integrate all ``simple enough'' functions
+into their callers with the option @option{-finline-functions}.
+
+GCC implements three different semantics of declaring a function
+inline. One is available with @option{-std=gnu89}, another when
+@option{-std=c99} or @option{-std=gnu99}, and the third is used when
+compiling C++.
To declare a function inline, use the @code{inline} keyword in its
declaration, like this:
@smallexample
-inline int
+static inline int
inc (int *a)
@{
(*a)++;
@}
@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}.)
-You can also make all ``simple enough'' functions inline with the option
-@option{-finline-functions}.
+If you are writing a header file to be included in ISO C89 programs, write
+@code{__inline__} instead of @code{inline}. @xref{Alternate Keywords}.
-@opindex Winline
-Note that certain usages in a function definition can make it unsuitable
-for inline substitution. Among these usages are: use of varargs, use of
-alloca, use of variable sized data types (@pxref{Variable Length}),
-use of computed goto (@pxref{Labels as Values}), use of nonlocal goto,
-and nested functions (@pxref{Nested Functions}). Using @option{-Winline}
-will warn when a function marked @code{inline} could not be substituted,
-and will give the reason for the failure.
+The three types of inlining behave similarly in two important cases:
+when the @code{inline} keyword is used on a @code{static} function,
+like the example above, and when a function is first declared without
+using the @code{inline} keyword and then is defined with
+@code{inline}, like this:
-Note that in C and Objective-C, unlike C++, the @code{inline} keyword
-does not affect the linkage of the function.
+@smallexample
+extern int inc (int *a);
+inline int
+inc (int *a)
+@{
+ (*a)++;
+@}
+@end smallexample
-@cindex automatic @code{inline} for C++ member fns
-@cindex @code{inline} automatic for C++ member fns
-@cindex member fns, automatically @code{inline}
-@cindex C++ member fns, automatically @code{inline}
-@opindex fno-default-inline
-GCC automatically inlines member functions defined within the class
-body of C++ programs even if they are not explicitly declared
-@code{inline}. (You can override this with @option{-fno-default-inline};
-@pxref{C++ Dialect Options,,Options Controlling C++ Dialect}.)
+In both of these common cases, the program behaves the same as if you
+had not used the @code{inline} keyword, except for its speed.
@cindex inline functions, omission of
@opindex fkeep-inline-functions
@@ -3904,6 +3892,27 @@ nonintegrated call, then the function is compiled to assembler code as
usual. The function must also be compiled as usual if the program
refers to its address, because that can't be inlined.
+@cindex automatic @code{inline} for C++ member fns
+@cindex @code{inline} automatic for C++ member fns
+@cindex member fns, automatically @code{inline}
+@cindex C++ member fns, automatically @code{inline}
+@opindex fno-default-inline
+As required by ISO C++, GCC considers member functions defined within
+the body of a class to be marked inline even if they are
+not explicitly declared with the @code{inline} keyword. You can
+override this with @option{-fno-default-inline}; @pxref{C++ Dialect
+Options,,Options Controlling C++ Dialect}.
+
+GCC does not inline any functions when not optimizing unless you specify
+the @samp{always_inline} attribute for the function, like this:
+
+@smallexample
+/* @r{Prototype.} */
+inline void foo (const char) __attribute__((always_inline));
+@end smallexample
+
+The remainder of this section is specific to GNU C89 inlining.
+
@cindex non-static inline function
When an inline function is not @code{static}, then the compiler must assume
that there may be calls from other source files; since a global symbol can
@@ -3926,24 +3935,6 @@ The definition in the header file will cause most calls to the function
to be inlined. If any uses of the function remain, they will refer to
the single copy in the library.
-Since GCC 4.3 will implement ISO C99 semantics for
-inline functions, it is simplest to use @code{static inline} only
-to guarantee compatibility. (The
-existing semantics will remain available when @option{-std=gnu89} is
-specified, but eventually the default will be @option{-std=gnu99};
-that will implement the C99 semantics, though it does not do so in
-versions of GCC before 4.3. After the default changes, the existing
-semantics will still be available via the @option{-fgnu89-inline}
-option or the @code{gnu_inline} function attribute.)
-
-GCC does not inline any functions when not optimizing unless you specify
-the @samp{always_inline} attribute for the function, like this:
-
-@smallexample
-/* @r{Prototype.} */
-inline void foo (const char) __attribute__((always_inline));
-@end smallexample
-
@node Extended Asm
@section Assembler Instructions with C Expression Operands
@cindex extended @code{asm}
OpenPOWER on IntegriCloud