473,322 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

extern and linkage

Consider

static int x;
void f()
{
extern int x; /* internal or external linkage? */
}

C99 6.2.2.4 says that "extern" causes an identifier's declaration to
inherit a previously specified linkage when it occurs "in a scope in
which a prior declaration of that identifier is visible". One might
think this means the inner x has internal linkage. Visual C++ 6 seems
to think so too.

But the footnote immediately afterward says, "As specified in 6.2.1
[scopes], the later declaration might hide the prior declaration." If
this footnote is to make sense, the inner x would have external
linkage, because its declaration hides that of the outer x. If so, it
is a bug in VC++ (which of course would not be all that surprising).

Which interpretation is correct?
Nov 14 '05 #1
1 1220
In article <50**************************@posting.google.com >
Steve Kobes <st*********@hotmail.com> writes:
Consider

static int x;
void f()
{
extern int x; /* internal or external linkage? */
}

C99 6.2.2.4 says that "extern" causes an identifier's declaration to
inherit a previously specified linkage when it occurs "in a scope in
which a prior declaration of that identifier is visible". One might
think this means the inner x has internal linkage. Visual C++ 6 seems
to think so too.
I believe this is correct.
But the footnote immediately afterward says, "As specified in 6.2.1
[scopes], the later declaration might hide the prior declaration." If
this footnote is to make sense, the inner x would have external
linkage, because its declaration hides that of the outer x. If so, it
is a bug in VC++ (which of course would not be all that surprising).


I believe this footnote refers instead to code such as this:

static int x;
void f(void) {
auto int x; /* hides "static" one; "auto" keyword for ref below */
{
extern int x;
...
}
}

Here the block-scope "auto" x has made the file-scope "x", with its
static duration, invisible. The "extern" line can no longer see it.

Note, however, that comp.lang.c is not the best group for questions
of the form: "what do these particular words in this particular
paragraph on this particular page of the C standard mean?" Along
with proposals for future standards, questions about interpretation
of current (and even past) standards is the domain of comp.std.c.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ik | last post by:
Hello all, Under C++ when 'extern' is used with out the string literal "C" does it act the same as a 'static' ? When is it appropriate using 'extern' ? Thanks ~Ik
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
12
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external...
19
by: ccwork | last post by:
Hi all, I am reading "C: A Reference Manual" 4th ed and I get lost for the "extern". It says that global object without specifying the storage-class specifier will have "extern" as the default...
29
by: DevarajA | last post by:
Can anyone explain me what extern is used for? I thought it was used to declare variables definited in other files, but i can do that also without extern. /*file a.c*/ int a=5; int main() {...
17
by: Tapeesh | last post by:
I would like to know what is the expected behaviour of C compilers when an extern decleration is intialized. When the following code is compiled using gcc //File extern.c int arr ; int a ;
5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
7
by: Christian Christmann | last post by:
Hi, I've a a question on the specifier extern. Code example: void func( void ) { extern int e; //...
3
by: coder | last post by:
While reading the page on "Reading C Declarations" <http://www.ericgiguere.com/articles/reading-c-declarations.html> (recommended by Mr. Heathfield at...
4
by: mimi | last post by:
The programmer indicates to the compiler that a function is written in a different programming language using a linkage directives.It is intuitive that extern "SomeLanguage" is used to declare...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.