external linkage or internal?

A

al.cpwn

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?
 
A

Alf P. Steinbach

* (e-mail address removed):
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

al.cpwn

Alf said:
* (e-mail address removed):

// 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.



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
 
R

Rolf Magnus

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.
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.
Again, why? What is the difference between extern inline void d() {}
and inline void() d{} if they both have external linkage?

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


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.
what does that mean?

That they are separate concepts that don't have anything to do with each
other.

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top