about external linkage question

K

Kurt

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
}
}

There are three objects named i. The object with internal
linkage
(line //1); the object with automatic storage duration and no
linkage (line //2); the object with static storage duration
and
external linkage (line //3).

question is:

I wonder the object i in line //3 refer to i in line //1. But
the
above said they are different thing.
help.
 
J

Jonathan Lane

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
}
}

There are three objects named i. The object with internal
linkage
(line //1); the object with automatic storage duration and no
linkage (line //2); the object with static storage duration
and
external linkage (line //3).

question is:

I wonder the object i in line //3 refer to i in line //1. But
the
above said they are different thing.
help.

Well it should be easy to determine if they're the same. Modify one
and test the value of the other. In this case they aren't. The extern
keyword effectively means, I've declared this in some other file, go
and find it there.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top