annotate doc/extern-inline.texi @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 10eb9086bea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17424
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
1 @c GNU extern-inline module documentation
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
2
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
3 @c Copyright (C) 2013-2019 Free Software Foundation, Inc.
17424
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
4
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
5 @c Permission is granted to copy, distribute and/or modify this document
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
6 @c under the terms of the GNU Free Documentation License, Version 1.3
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
7 @c or any later version published by the Free Software Foundation;
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
8 @c with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9 @c Texts. A copy of the license is included in the ``GNU Free
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10 @c Documentation License'' file as part of this distribution.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12 @c Written by Paul Eggert.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14 @node extern inline
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
15 @section Extern inline functions
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
16
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
17 @cindex extern inline
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
18 @cindex inline
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
20 The @code{extern-inline} module supports the use of C99-style
18812
06504a1de0ad Target a C99 subset, not a C89 subset
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
21 @code{extern inline} functions so that the code still runs on
06504a1de0ad Target a C99 subset, not a C89 subset
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
22 compilers that do not support this feature correctly.
17424
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
23
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
24 C code ordinarily should not use @code{inline}. Typically it is
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
25 better to let the compiler figure out whether to inline, as compilers
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
26 are pretty good about optimization nowadays. In this sense,
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
27 @code{inline} is like @code{register}, another keyword that is
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
28 typically no longer needed.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
29
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
30 Functions defined (not merely declared) in headers are an exception,
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
31 as avoiding @code{inline} would commonly cause problems for these
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
32 functions. Suppose @file{aaa.h} defines the function @code{aaa_fun},
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
33 and @file{aaa.c}, @file{bbb.c} and @file{ccc.c} all include
18812
06504a1de0ad Target a C99 subset, not a C89 subset
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
34 @file{aaa.h}. If code is intended to portable to non-C99 compilers,
17424
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
35 @code{aaa_fun} cannot be declared with the C99 @code{inline} keyword.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
36 This problem cannot be worked around by making @code{aaa_fun} an
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
37 ordinary function, as it would be defined three times with external
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
38 linkage and the definitions would clash. Although @code{aaa_fun}
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
39 could be a static function, with separate compilation if
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
40 @code{aaa_fun} is not inlined its code will appear in the executable
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
41 three times.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
42
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
43 To avoid this code bloat, @file{aaa.h} can do this:
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
44
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
45 @example
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
46 /* aaa.h */
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
47 /* #include any other headers here */
17473
1f9070ef79b0 headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents: 17424
diff changeset
48 #ifndef _GL_INLINE_HEADER_BEGIN
1f9070ef79b0 headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents: 17424
diff changeset
49 #error "Please include config.h first."
1f9070ef79b0 headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents: 17424
diff changeset
50 #endif
17424
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
51 _GL_INLINE_HEADER_BEGIN
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
52 #ifndef AAA_INLINE
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
53 # define AAA_INLINE _GL_INLINE
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
54 #endif
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
55 ...
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
56 AAA_INLINE int
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
57 aaa_fun (int i)
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
58 @{
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
59 return i + 1;
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
60 @}
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
61 ...
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
62 _GL_INLINE_HEADER_END
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
63 @end example
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
64
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
65 @noindent
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
66 and @file{aaa.c} can do this:
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
67
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
68 @example
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
69 /* aaa.c */
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
70 #include <config.h>
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
71 #define AAA_INLINE _GL_EXTERN_INLINE
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
72 #include <aaa.h>
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
73 @end example
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
74
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
75 @noindent
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
76 whereas @file{bbb.c} and @file{ccc.c} can include @file{aaa.h} in the
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
77 usual way. C99 compilers expand @code{AAA_INLINE} to C99-style
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
78 @code{inline} usage, where @code{aaa_fun} is declared @code{extern
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
79 inline} in @file{aaa.c} and plain @code{inline} in other modules.
18812
06504a1de0ad Target a C99 subset, not a C89 subset
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
80 Non-C99 compilers that are compatible with GCC use GCC-specific syntax
06504a1de0ad Target a C99 subset, not a C89 subset
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
81 to accomplish the same ends. Other non-C99 compilers use @code{static
17424
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
82 inline} so they suffer from code bloat, but they are not mainline
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
83 platforms and will die out eventually.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
84
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
85 @findex _GL_INLINE
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
86 @code{_GL_INLINE} is a portable alternative to C99 plain @code{inline}.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
87
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
88 @findex _GL_EXTERN_INLINE
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
89 @code{_GL_EXTERN_INLINE} is a portable alternative to C99 @code{extern inline}.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
90
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
91 @findex _GL_INLINE_HEADER_BEGIN
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
92 Invoke @code{_GL_INLINE_HEADER_BEGIN} before all uses of
17978
144717f4f8b0 extern-inline: no need for workaround in GCC 5.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
93 @code{_GL_INLINE} in an include file. This suppresses some
144717f4f8b0 extern-inline: no need for workaround in GCC 5.1
Paul Eggert <eggert@cs.ucla.edu>
parents: 17848
diff changeset
94 bogus warnings in GCC versions before 5.1. If an include file includes
17424
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
95 other files, it is better to invoke this macro after including the
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
96 other files.
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
97
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
98 @findex _GL_INLINE_HEADER_END
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
99 Invoke @code{_GL_INLINE_HEADER_END} after all uses of
a0d0b52b7d06 doc: document extern-inline
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
100 @code{_GL_INLINE} in an include file.