"Grumble" <de*****@kma.eu .org> wrote in message
news:cu******** **@news-rocq.inria.fr.. .
Hello everyone,
As far as I understand, the 'inline' keyword is a hint for the compiler
to consider the function in question as a candidate for inlining, yes?
Yes.
What happens when a function with extern linkage is inlined?
Nothing special.
Should the
compiler still export the function?
Unless it's explicitly specified as static, it has
external linkage, whether it's declared inline or not.
But there is a further requirement about an inline
function *definition*, cited below.
Or is an inlined function implicitly static?
No.
Is extern inline foo() { } a legal function defintion?
Yes.
Is inline foo(...) { } different from inline foo() { } ?
Yes, the signatures are different.
I was somewhat confused after reading
http://cpptips.hyperformix.com/cpptips/extern_inline3
$ cat foo.cxx
extern inline int foo(int n)
{
int sum = 0;
for (int i = 0; i < n; ++i) sum += i;
return sum;
}
$ g++-3.4.3 -std=c++98 -Wall -Wextra -pedantic -c foo.cxx
$ nm foo.o
/* NO SYMBOLS EXPORTED */
=============== =============== =============== =============== ====
ISO/IEC 14882:1998(E)
.....
3.2 One definition rule
3 Every program shall contain exactly one definition of every
non*inline function or object that is used in that program;
no diagnostic required. The definition can appear explicitly
in the program, it can be found in the standard or a user-
*defined library, or (when appropriate) it is implicitly defined
(see 12.1, 12.4 and 12.8). An inline function shall be defined
in every translation unit in which it is used.
.....
3.5 Program and linkage
3 A name having namespace scope (3.3.5) has internal linkage
if it is the name of
-- an object, reference, function or function template that
is explicitly declared static or,
-- an object or reference that is explicitly declared const
and neither explicitly declared extern nor previously
declared to have external linkage; or
-- a data member of an anonymous union.
4 A name having namespace scope has external linkage if it is
the name of
-- an object or reference, unless it has internal linkage; or
-- a function, unless it has internal linkage; or
-- a named class (clause 9), or an unnamed class defined in
a typedef declaration in which the class has the
typedef name for linkage purposes (7.1.3); or
-- a named enumeration (7.2), or an unnamed enumeration defined
in a typedef declaration in which the
enumeration has the typedef name for linkage purposes
(7.1.3); or
-- an enumerator belonging to an enumeration with external
linkage; or
-- a template, unless it is a function template that has internal
linkage (clause 14); or
-- a namespace (7.3), unless it is declared within an unnamed
namespace.
.....
7.1.2 Function specifiers
4 An inline function shall be defined in every translation
unit in which it is used and shall have exactly the same
definition in every case (3.2). [Note: a call to the inline
function may be encountered before its defi*nition appears
in the translation unit. ] If a function with external
linkage is declared inline in one transla*tion unit, it
shall be declared inline in all translation units in which
it appears; no diagnostic is required. An inline function
with external linkage shall have the same address in all
translation units. A static local variable in an extern
inline function always refers to the same object. A string
literal in an extern inline function is the same object in
different translation units.
=============== =============== =============== =============== ====
-Mike