By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,314 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,314 IT Pros & Developers. It's quick & easy.

external linkage or internal?

P: n/a
do static and inline functions or members have internal linkage? I have
been reading this newsgroup on google and found conflicting ideas. Can
someone please help me understand why in some places inline may have
external linkage while in others it has internal (from what I have read
in comments by people). Are there any (other) places where linkage is
ambiguous?

Mar 8 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
* al*****@gmail.com:
do static and inline functions or members have internal linkage? I have
been reading this newsgroup on google and found conflicting ideas. Can
someone please help me understand why in some places inline may have
external linkage while in others it has internal (from what I have read
in comments by people).
// External linkage
void a() {}

// External linkage
inline void b() {}

// External linkage
extern void c() {}

// External linkage
extern inline void d() {}

// External linkage
struct Foo1{ static void e(); };
void Foo1::e() {}

// External linkage
struct Foo2{ static void f() {} };

// External linkage
struct Foo3{ void g(); }
void Foo3::g() {}

// External linkage
struct Foo4{ void h() {} }

// Internal linkage
static void i() {}

// Internal linkage
static inline void j() {}

void aFunction()
{
// No linkage.
struct aStruct
{
...
};
}

Summing up, 'inline' is orthogonal to extern/internal linkage.

However, 'inline' places an extra requirement, that of identical
definitions in different translation units, on a function with extern
linkage.

Are there any (other) places where linkage is ambiguous?


I don't think there's any case of ambigious linkage.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Mar 8 '06 #2

P: n/a
Alf P. Steinbach wrote:
* al*****@gmail.com:
do static and inline functions or members have internal linkage? I have
been reading this newsgroup on google and found conflicting ideas. Can
someone please help me understand why in some places inline may have
external linkage while in others it has internal (from what I have read
in comments by people).
// External linkage
void a() {}


aren't members declared at file scope static implicitly? So even if
void a() {} has external linkage, something like

int x;

should will be static and hence will have internal linkage.

// External linkage
inline void b() {}
Here I am confused. Lakos mentions that inline functions have internal
linkage (1.1.2, pg 24). Why should the above example have external
linkage then?

// External linkage
extern void c() {}
undertood

// External linkage
extern inline void d() {}
Again, why? What is the difference between extern inline void d() {}
and inline void() d{} if they both have external linkage?

// External linkage
struct Foo1{ static void e(); };
void Foo1::e() {}
wow is there a quick way of determining or these have to be memorized?

// External linkage
struct Foo2{ static void f() {} };
well, here static void f() {} is inline as it is also defined where it
is declared in the struct. Lakos mentions that this too should have
internal linkage.

// External linkage
struct Foo3{ void g(); }
void Foo3::g() {}

// External linkage
struct Foo4{ void h() {} }

// Internal linkage
static void i() {}

// Internal linkage
static inline void j() {}

void aFunction()
{
// No linkage.
struct aStruct
{
...
};
}

Summing up, 'inline' is orthogonal to extern/internal linkage.
what does that mean?

However, 'inline' places an extra requirement, that of identical
definitions in different translation units, on a function with extern
linkage.

> Are there any (other) places where linkage is ambiguous?


I don't think there's any case of ambigious linkage.


thanks, but I was only wondering how inline can have internal linkage
or external

Mar 8 '06 #3

P: n/a
al*****@gmail.com wrote:
Alf P. Steinbach wrote:
* al*****@gmail.com:
> do static and inline functions or members have internal linkage? I have
> been reading this newsgroup on google and found conflicting ideas. Can
> someone please help me understand why in some places inline may have
> external linkage while in others it has internal (from what I have read
> in comments by people).
// External linkage
void a() {}


aren't members declared at file scope static implicitly?


This is not a member. And no.
So even if void a() {} has external linkage, something like

int x;

should will be static and hence will have internal linkage.
Not unless it is also declared const.
// External linkage
inline void b() {}


Here I am confused. Lakos mentions that inline functions have internal
linkage (1.1.2, pg 24).


Who is Lakos?
Why should the above example have external linkage then?


Because the C++ standard says so.
// External linkage
extern void c() {}


undertood

// External linkage
extern inline void d() {}


Again, why? What is the difference between extern inline void d() {}
and inline void() d{} if they both have external linkage?


Uhm, nothing?
// External linkage
struct Foo1{ static void e(); };
void Foo1::e() {}


wow is there a quick way of determining or these have to be memorized?

// External linkage
struct Foo2{ static void f() {} };


well, here static void f() {} is inline as it is also defined where it
is declared in the struct. Lakos mentions that this too should have
internal linkage.


Then Lakos is wrong.
// External linkage
struct Foo3{ void g(); }
void Foo3::g() {}

// External linkage
struct Foo4{ void h() {} }

// Internal linkage
static void i() {}

// Internal linkage
static inline void j() {}

void aFunction()
{
// No linkage.
struct aStruct
{
...
};
}

Summing up, 'inline' is orthogonal to extern/internal linkage.


what does that mean?


That they are separate concepts that don't have anything to do with each
other.
However, 'inline' places an extra requirement, that of identical
definitions in different translation units, on a function with extern
linkage.


Actually, I would have said it frees you from the extra requirement of never
defining an extern function more than once (aka one definition rule).

Mar 8 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.