472,794 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

external linkage or internal?

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
3 5943
* 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
4
by: Tron Thomas | last post by:
I have read that anonymous namespaces are preferred in C++ over declaring global statics because the namespace can hide information from other translation units and at the same time provide...
2
by: Lu | last post by:
Hello, I am wondering how to protect a global variable in a header file from external access. So I googled and found: "The keyword 'static' has two different uses, depending on whether it is...
9
by: maxw_cc | last post by:
Hi to all, To explain my question I'll help myself with the following two code snippets: /*** file1.c ***/ #include <stdio.h> void print_it(void);
19
by: J. J. Farrell | last post by:
After many years of dealing with definition and linkage issues in ways that I know to be safe, I've decided it's time to try to understand this area properly. Consider a header file with the file...
4
by: Peter Ammon | last post by:
I would like to share a variable between two functions defined in two separate source files; no other functions will need the global variable so I'd prefer to not give it file scope. Thus, I want...
0
by: himnish | last post by:
hi, I'm trying to compile opensource snort-2.6.1.3 with HP-UX aCC compiler. While compiling I'm getting the issue like line 1589: error #3031-D: an entity with internal linkage cannot...
1
by: Kurt | last post by:
The C++ standard (in 3.5:6, p42Example) said: static int i = 0; // 1 void g() { int i; //2: i has no linkage { extern int i; //3: external linkage
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.