Extern declaration on an extern “C” global variable
In C and C++ if I want to use a global variable in other compilation units I will define the variable like:
int g_myVal = 0;
This allocates storage for the int
.
In the header file I then declare the variable:
extern int g_myVal;
This informs the compiler that said symbol exists in some other compilation unit. It is then up to the linker to resolve the symbol.
However if I want the variable to be available with "C" linkage I must define the variable (allocate storage) like:
extern "C" int g_myVal = 0;
So how does one then differentiate between allocating storage and just informing the compiler that said symbol exists in another compilation unit?
c++
add a comment |
In C and C++ if I want to use a global variable in other compilation units I will define the variable like:
int g_myVal = 0;
This allocates storage for the int
.
In the header file I then declare the variable:
extern int g_myVal;
This informs the compiler that said symbol exists in some other compilation unit. It is then up to the linker to resolve the symbol.
However if I want the variable to be available with "C" linkage I must define the variable (allocate storage) like:
extern "C" int g_myVal = 0;
So how does one then differentiate between allocating storage and just informing the compiler that said symbol exists in another compilation unit?
c++
Shouldn't the declaration beextern int g_myVal;
?
– jbgs
Jan 9 '14 at 16:52
@jbgs: Yes.
– Lightness Races in Orbit
Jan 9 '14 at 16:52
add a comment |
In C and C++ if I want to use a global variable in other compilation units I will define the variable like:
int g_myVal = 0;
This allocates storage for the int
.
In the header file I then declare the variable:
extern int g_myVal;
This informs the compiler that said symbol exists in some other compilation unit. It is then up to the linker to resolve the symbol.
However if I want the variable to be available with "C" linkage I must define the variable (allocate storage) like:
extern "C" int g_myVal = 0;
So how does one then differentiate between allocating storage and just informing the compiler that said symbol exists in another compilation unit?
c++
In C and C++ if I want to use a global variable in other compilation units I will define the variable like:
int g_myVal = 0;
This allocates storage for the int
.
In the header file I then declare the variable:
extern int g_myVal;
This informs the compiler that said symbol exists in some other compilation unit. It is then up to the linker to resolve the symbol.
However if I want the variable to be available with "C" linkage I must define the variable (allocate storage) like:
extern "C" int g_myVal = 0;
So how does one then differentiate between allocating storage and just informing the compiler that said symbol exists in another compilation unit?
c++
c++
edited Dec 28 '18 at 23:36
Jonathan Leffler
562k896701021
562k896701021
asked Jan 9 '14 at 16:48
dorondoron
18.5k64882
18.5k64882
Shouldn't the declaration beextern int g_myVal;
?
– jbgs
Jan 9 '14 at 16:52
@jbgs: Yes.
– Lightness Races in Orbit
Jan 9 '14 at 16:52
add a comment |
Shouldn't the declaration beextern int g_myVal;
?
– jbgs
Jan 9 '14 at 16:52
@jbgs: Yes.
– Lightness Races in Orbit
Jan 9 '14 at 16:52
Shouldn't the declaration be
extern int g_myVal;
?– jbgs
Jan 9 '14 at 16:52
Shouldn't the declaration be
extern int g_myVal;
?– jbgs
Jan 9 '14 at 16:52
@jbgs: Yes.
– Lightness Races in Orbit
Jan 9 '14 at 16:52
@jbgs: Yes.
– Lightness Races in Orbit
Jan 9 '14 at 16:52
add a comment |
2 Answers
2
active
oldest
votes
Your confusion stems from the fact that extern
and extern "C"
do two different things.
About extern
extern
on its own is a storage class specifier:
[C++11: 7.1.1/6]:
Theextern
specifier can be applied only to the names of variables and functions. Theextern
specifier cannot be used in the declaration of class members or function parameters. For the linkage of a name declared with anextern
specifier, see 3.5. [ Note: Theextern
keyword can also be used in explicit-instantiations and linkage-specifications, but it is not a storage-class-specifier in such contexts. —end note ]
About extern "C"
As that trailing note alludes to, there is another context in which you may use the extern
keyword and that is as a linkage specifier:
[C++11: 7.5/2]:
Linkage (3.5) between C++ and non-C++ code fragments can be achieved using a linkage-specification:
linkage-specification:
extern
string-literal{
declaration-seqopt}
extern
string-literal declaration
C++ likes to re-use keywords.
Declarations vs definitions
Now, by default, a variable marked with a linkage specifier is a declaration rather than a definition, so in that sense it is as if you had also used the other meaning of extern
:
[C++11: 7.5/7]:
A declaration directly contained in a linkage-specification is treated as if it contains theextern
specifier (7.1.1) for the purpose of determining the linkage of the declared name and whether it is a definition. Such a declaration shall not specify a storage class. [ Example:
extern "C" double f();
static double f(); // error
extern "C" int i; // declaration
extern "C" {
int i; // definition
}
extern "C" static void g(); // error
— end example ]
As you can see in the above example, it is still possible to either a declaration or a definition when you use a linkage specifier.
Here's another example of that:
// Everything in this block has C linkage
extern "C" {
// Declaration of g_myVal
extern int g_myVal;
// Definition of g_myVal2
int g_myVal2;
}
int main()
{
g_myVal2 = 5; // ok
g_myVal = 6; // not okay - linker error, symbol not found
}
Live demo
When you add an initialiser...
That all being said, the treatment of g_myVal
as a declaration is overruled by your use of an initialiser, which forces the statement to be a definition:
[C++11: 7/8]:
Syntactic components beyond those found in the general form of declaration are added to a function declaration to make a function-definition. An object declaration, however, is also a definition unless it contains theextern
specifier and has no initializer (3.1). A definition causes the appropriate amount of storage to be reserved and any appropriate initialization (8.5) to be done.
I hope that this clarifies what is going on in your code with these differing meanings of extern
.
theextern
forg_myVal
is redundant.
– user2485710
Jan 9 '14 at 16:59
@user2485710: No, it isn't.
– Lightness Races in Orbit
Jan 9 '14 at 17:03
try to put theextern
alized symbols in another translation unit ...
– user2485710
Jan 9 '14 at 17:06
@user2485710: What does another translation unit have to do with it? I provided a live demo, as well as standard quotes, that all say the same thing: theextern
is absolutely not redundant. It changes the meaning of the declaration in a significant way.
– Lightness Races in Orbit
Jan 9 '14 at 17:09
@user2485710: Oh, did you mean theg_myVal
in the original code, the one with the initialiser? Yes, it's redundant there because the statement is a definition anyway, because it has an initialiser. That is true. But not the other statement, and none in my answer, nor in the example from the standard.
– Lightness Races in Orbit
Jan 9 '14 at 17:13
add a comment |
In this case, putting the initializer = 0
changed the declaration to a definition, which is why storage is allocated here. (The same would have happened even with just plain extern
.)
A good point. :)
– Lightness Races in Orbit
Jan 9 '14 at 17:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21026264%2fextern-declaration-on-an-extern-c-global-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your confusion stems from the fact that extern
and extern "C"
do two different things.
About extern
extern
on its own is a storage class specifier:
[C++11: 7.1.1/6]:
Theextern
specifier can be applied only to the names of variables and functions. Theextern
specifier cannot be used in the declaration of class members or function parameters. For the linkage of a name declared with anextern
specifier, see 3.5. [ Note: Theextern
keyword can also be used in explicit-instantiations and linkage-specifications, but it is not a storage-class-specifier in such contexts. —end note ]
About extern "C"
As that trailing note alludes to, there is another context in which you may use the extern
keyword and that is as a linkage specifier:
[C++11: 7.5/2]:
Linkage (3.5) between C++ and non-C++ code fragments can be achieved using a linkage-specification:
linkage-specification:
extern
string-literal{
declaration-seqopt}
extern
string-literal declaration
C++ likes to re-use keywords.
Declarations vs definitions
Now, by default, a variable marked with a linkage specifier is a declaration rather than a definition, so in that sense it is as if you had also used the other meaning of extern
:
[C++11: 7.5/7]:
A declaration directly contained in a linkage-specification is treated as if it contains theextern
specifier (7.1.1) for the purpose of determining the linkage of the declared name and whether it is a definition. Such a declaration shall not specify a storage class. [ Example:
extern "C" double f();
static double f(); // error
extern "C" int i; // declaration
extern "C" {
int i; // definition
}
extern "C" static void g(); // error
— end example ]
As you can see in the above example, it is still possible to either a declaration or a definition when you use a linkage specifier.
Here's another example of that:
// Everything in this block has C linkage
extern "C" {
// Declaration of g_myVal
extern int g_myVal;
// Definition of g_myVal2
int g_myVal2;
}
int main()
{
g_myVal2 = 5; // ok
g_myVal = 6; // not okay - linker error, symbol not found
}
Live demo
When you add an initialiser...
That all being said, the treatment of g_myVal
as a declaration is overruled by your use of an initialiser, which forces the statement to be a definition:
[C++11: 7/8]:
Syntactic components beyond those found in the general form of declaration are added to a function declaration to make a function-definition. An object declaration, however, is also a definition unless it contains theextern
specifier and has no initializer (3.1). A definition causes the appropriate amount of storage to be reserved and any appropriate initialization (8.5) to be done.
I hope that this clarifies what is going on in your code with these differing meanings of extern
.
theextern
forg_myVal
is redundant.
– user2485710
Jan 9 '14 at 16:59
@user2485710: No, it isn't.
– Lightness Races in Orbit
Jan 9 '14 at 17:03
try to put theextern
alized symbols in another translation unit ...
– user2485710
Jan 9 '14 at 17:06
@user2485710: What does another translation unit have to do with it? I provided a live demo, as well as standard quotes, that all say the same thing: theextern
is absolutely not redundant. It changes the meaning of the declaration in a significant way.
– Lightness Races in Orbit
Jan 9 '14 at 17:09
@user2485710: Oh, did you mean theg_myVal
in the original code, the one with the initialiser? Yes, it's redundant there because the statement is a definition anyway, because it has an initialiser. That is true. But not the other statement, and none in my answer, nor in the example from the standard.
– Lightness Races in Orbit
Jan 9 '14 at 17:13
add a comment |
Your confusion stems from the fact that extern
and extern "C"
do two different things.
About extern
extern
on its own is a storage class specifier:
[C++11: 7.1.1/6]:
Theextern
specifier can be applied only to the names of variables and functions. Theextern
specifier cannot be used in the declaration of class members or function parameters. For the linkage of a name declared with anextern
specifier, see 3.5. [ Note: Theextern
keyword can also be used in explicit-instantiations and linkage-specifications, but it is not a storage-class-specifier in such contexts. —end note ]
About extern "C"
As that trailing note alludes to, there is another context in which you may use the extern
keyword and that is as a linkage specifier:
[C++11: 7.5/2]:
Linkage (3.5) between C++ and non-C++ code fragments can be achieved using a linkage-specification:
linkage-specification:
extern
string-literal{
declaration-seqopt}
extern
string-literal declaration
C++ likes to re-use keywords.
Declarations vs definitions
Now, by default, a variable marked with a linkage specifier is a declaration rather than a definition, so in that sense it is as if you had also used the other meaning of extern
:
[C++11: 7.5/7]:
A declaration directly contained in a linkage-specification is treated as if it contains theextern
specifier (7.1.1) for the purpose of determining the linkage of the declared name and whether it is a definition. Such a declaration shall not specify a storage class. [ Example:
extern "C" double f();
static double f(); // error
extern "C" int i; // declaration
extern "C" {
int i; // definition
}
extern "C" static void g(); // error
— end example ]
As you can see in the above example, it is still possible to either a declaration or a definition when you use a linkage specifier.
Here's another example of that:
// Everything in this block has C linkage
extern "C" {
// Declaration of g_myVal
extern int g_myVal;
// Definition of g_myVal2
int g_myVal2;
}
int main()
{
g_myVal2 = 5; // ok
g_myVal = 6; // not okay - linker error, symbol not found
}
Live demo
When you add an initialiser...
That all being said, the treatment of g_myVal
as a declaration is overruled by your use of an initialiser, which forces the statement to be a definition:
[C++11: 7/8]:
Syntactic components beyond those found in the general form of declaration are added to a function declaration to make a function-definition. An object declaration, however, is also a definition unless it contains theextern
specifier and has no initializer (3.1). A definition causes the appropriate amount of storage to be reserved and any appropriate initialization (8.5) to be done.
I hope that this clarifies what is going on in your code with these differing meanings of extern
.
theextern
forg_myVal
is redundant.
– user2485710
Jan 9 '14 at 16:59
@user2485710: No, it isn't.
– Lightness Races in Orbit
Jan 9 '14 at 17:03
try to put theextern
alized symbols in another translation unit ...
– user2485710
Jan 9 '14 at 17:06
@user2485710: What does another translation unit have to do with it? I provided a live demo, as well as standard quotes, that all say the same thing: theextern
is absolutely not redundant. It changes the meaning of the declaration in a significant way.
– Lightness Races in Orbit
Jan 9 '14 at 17:09
@user2485710: Oh, did you mean theg_myVal
in the original code, the one with the initialiser? Yes, it's redundant there because the statement is a definition anyway, because it has an initialiser. That is true. But not the other statement, and none in my answer, nor in the example from the standard.
– Lightness Races in Orbit
Jan 9 '14 at 17:13
add a comment |
Your confusion stems from the fact that extern
and extern "C"
do two different things.
About extern
extern
on its own is a storage class specifier:
[C++11: 7.1.1/6]:
Theextern
specifier can be applied only to the names of variables and functions. Theextern
specifier cannot be used in the declaration of class members or function parameters. For the linkage of a name declared with anextern
specifier, see 3.5. [ Note: Theextern
keyword can also be used in explicit-instantiations and linkage-specifications, but it is not a storage-class-specifier in such contexts. —end note ]
About extern "C"
As that trailing note alludes to, there is another context in which you may use the extern
keyword and that is as a linkage specifier:
[C++11: 7.5/2]:
Linkage (3.5) between C++ and non-C++ code fragments can be achieved using a linkage-specification:
linkage-specification:
extern
string-literal{
declaration-seqopt}
extern
string-literal declaration
C++ likes to re-use keywords.
Declarations vs definitions
Now, by default, a variable marked with a linkage specifier is a declaration rather than a definition, so in that sense it is as if you had also used the other meaning of extern
:
[C++11: 7.5/7]:
A declaration directly contained in a linkage-specification is treated as if it contains theextern
specifier (7.1.1) for the purpose of determining the linkage of the declared name and whether it is a definition. Such a declaration shall not specify a storage class. [ Example:
extern "C" double f();
static double f(); // error
extern "C" int i; // declaration
extern "C" {
int i; // definition
}
extern "C" static void g(); // error
— end example ]
As you can see in the above example, it is still possible to either a declaration or a definition when you use a linkage specifier.
Here's another example of that:
// Everything in this block has C linkage
extern "C" {
// Declaration of g_myVal
extern int g_myVal;
// Definition of g_myVal2
int g_myVal2;
}
int main()
{
g_myVal2 = 5; // ok
g_myVal = 6; // not okay - linker error, symbol not found
}
Live demo
When you add an initialiser...
That all being said, the treatment of g_myVal
as a declaration is overruled by your use of an initialiser, which forces the statement to be a definition:
[C++11: 7/8]:
Syntactic components beyond those found in the general form of declaration are added to a function declaration to make a function-definition. An object declaration, however, is also a definition unless it contains theextern
specifier and has no initializer (3.1). A definition causes the appropriate amount of storage to be reserved and any appropriate initialization (8.5) to be done.
I hope that this clarifies what is going on in your code with these differing meanings of extern
.
Your confusion stems from the fact that extern
and extern "C"
do two different things.
About extern
extern
on its own is a storage class specifier:
[C++11: 7.1.1/6]:
Theextern
specifier can be applied only to the names of variables and functions. Theextern
specifier cannot be used in the declaration of class members or function parameters. For the linkage of a name declared with anextern
specifier, see 3.5. [ Note: Theextern
keyword can also be used in explicit-instantiations and linkage-specifications, but it is not a storage-class-specifier in such contexts. —end note ]
About extern "C"
As that trailing note alludes to, there is another context in which you may use the extern
keyword and that is as a linkage specifier:
[C++11: 7.5/2]:
Linkage (3.5) between C++ and non-C++ code fragments can be achieved using a linkage-specification:
linkage-specification:
extern
string-literal{
declaration-seqopt}
extern
string-literal declaration
C++ likes to re-use keywords.
Declarations vs definitions
Now, by default, a variable marked with a linkage specifier is a declaration rather than a definition, so in that sense it is as if you had also used the other meaning of extern
:
[C++11: 7.5/7]:
A declaration directly contained in a linkage-specification is treated as if it contains theextern
specifier (7.1.1) for the purpose of determining the linkage of the declared name and whether it is a definition. Such a declaration shall not specify a storage class. [ Example:
extern "C" double f();
static double f(); // error
extern "C" int i; // declaration
extern "C" {
int i; // definition
}
extern "C" static void g(); // error
— end example ]
As you can see in the above example, it is still possible to either a declaration or a definition when you use a linkage specifier.
Here's another example of that:
// Everything in this block has C linkage
extern "C" {
// Declaration of g_myVal
extern int g_myVal;
// Definition of g_myVal2
int g_myVal2;
}
int main()
{
g_myVal2 = 5; // ok
g_myVal = 6; // not okay - linker error, symbol not found
}
Live demo
When you add an initialiser...
That all being said, the treatment of g_myVal
as a declaration is overruled by your use of an initialiser, which forces the statement to be a definition:
[C++11: 7/8]:
Syntactic components beyond those found in the general form of declaration are added to a function declaration to make a function-definition. An object declaration, however, is also a definition unless it contains theextern
specifier and has no initializer (3.1). A definition causes the appropriate amount of storage to be reserved and any appropriate initialization (8.5) to be done.
I hope that this clarifies what is going on in your code with these differing meanings of extern
.
edited Oct 31 '14 at 0:20
answered Jan 9 '14 at 16:52
Lightness Races in OrbitLightness Races in Orbit
287k51466788
287k51466788
theextern
forg_myVal
is redundant.
– user2485710
Jan 9 '14 at 16:59
@user2485710: No, it isn't.
– Lightness Races in Orbit
Jan 9 '14 at 17:03
try to put theextern
alized symbols in another translation unit ...
– user2485710
Jan 9 '14 at 17:06
@user2485710: What does another translation unit have to do with it? I provided a live demo, as well as standard quotes, that all say the same thing: theextern
is absolutely not redundant. It changes the meaning of the declaration in a significant way.
– Lightness Races in Orbit
Jan 9 '14 at 17:09
@user2485710: Oh, did you mean theg_myVal
in the original code, the one with the initialiser? Yes, it's redundant there because the statement is a definition anyway, because it has an initialiser. That is true. But not the other statement, and none in my answer, nor in the example from the standard.
– Lightness Races in Orbit
Jan 9 '14 at 17:13
add a comment |
theextern
forg_myVal
is redundant.
– user2485710
Jan 9 '14 at 16:59
@user2485710: No, it isn't.
– Lightness Races in Orbit
Jan 9 '14 at 17:03
try to put theextern
alized symbols in another translation unit ...
– user2485710
Jan 9 '14 at 17:06
@user2485710: What does another translation unit have to do with it? I provided a live demo, as well as standard quotes, that all say the same thing: theextern
is absolutely not redundant. It changes the meaning of the declaration in a significant way.
– Lightness Races in Orbit
Jan 9 '14 at 17:09
@user2485710: Oh, did you mean theg_myVal
in the original code, the one with the initialiser? Yes, it's redundant there because the statement is a definition anyway, because it has an initialiser. That is true. But not the other statement, and none in my answer, nor in the example from the standard.
– Lightness Races in Orbit
Jan 9 '14 at 17:13
the
extern
for g_myVal
is redundant.– user2485710
Jan 9 '14 at 16:59
the
extern
for g_myVal
is redundant.– user2485710
Jan 9 '14 at 16:59
@user2485710: No, it isn't.
– Lightness Races in Orbit
Jan 9 '14 at 17:03
@user2485710: No, it isn't.
– Lightness Races in Orbit
Jan 9 '14 at 17:03
try to put the
extern
alized symbols in another translation unit ...– user2485710
Jan 9 '14 at 17:06
try to put the
extern
alized symbols in another translation unit ...– user2485710
Jan 9 '14 at 17:06
@user2485710: What does another translation unit have to do with it? I provided a live demo, as well as standard quotes, that all say the same thing: the
extern
is absolutely not redundant. It changes the meaning of the declaration in a significant way.– Lightness Races in Orbit
Jan 9 '14 at 17:09
@user2485710: What does another translation unit have to do with it? I provided a live demo, as well as standard quotes, that all say the same thing: the
extern
is absolutely not redundant. It changes the meaning of the declaration in a significant way.– Lightness Races in Orbit
Jan 9 '14 at 17:09
@user2485710: Oh, did you mean the
g_myVal
in the original code, the one with the initialiser? Yes, it's redundant there because the statement is a definition anyway, because it has an initialiser. That is true. But not the other statement, and none in my answer, nor in the example from the standard.– Lightness Races in Orbit
Jan 9 '14 at 17:13
@user2485710: Oh, did you mean the
g_myVal
in the original code, the one with the initialiser? Yes, it's redundant there because the statement is a definition anyway, because it has an initialiser. That is true. But not the other statement, and none in my answer, nor in the example from the standard.– Lightness Races in Orbit
Jan 9 '14 at 17:13
add a comment |
In this case, putting the initializer = 0
changed the declaration to a definition, which is why storage is allocated here. (The same would have happened even with just plain extern
.)
A good point. :)
– Lightness Races in Orbit
Jan 9 '14 at 17:11
add a comment |
In this case, putting the initializer = 0
changed the declaration to a definition, which is why storage is allocated here. (The same would have happened even with just plain extern
.)
A good point. :)
– Lightness Races in Orbit
Jan 9 '14 at 17:11
add a comment |
In this case, putting the initializer = 0
changed the declaration to a definition, which is why storage is allocated here. (The same would have happened even with just plain extern
.)
In this case, putting the initializer = 0
changed the declaration to a definition, which is why storage is allocated here. (The same would have happened even with just plain extern
.)
answered Jan 9 '14 at 17:01
tabstoptabstop
1,65379
1,65379
A good point. :)
– Lightness Races in Orbit
Jan 9 '14 at 17:11
add a comment |
A good point. :)
– Lightness Races in Orbit
Jan 9 '14 at 17:11
A good point. :)
– Lightness Races in Orbit
Jan 9 '14 at 17:11
A good point. :)
– Lightness Races in Orbit
Jan 9 '14 at 17:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21026264%2fextern-declaration-on-an-extern-c-global-variable%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Shouldn't the declaration be
extern int g_myVal;
?– jbgs
Jan 9 '14 at 16:52
@jbgs: Yes.
– Lightness Races in Orbit
Jan 9 '14 at 16:52