Topic: Linkage and the Standard
Author: whayes@hfx.andara.com ("William Hayes")
Date: Wed, 30 Apr 2003 18:42:52 +0000 (UTC) Raw View
"Stephen Clamage" <stephen.clamage@sun.com> wrote in message
news:ejfpavk6d1etftqbq4hrgj5g7g0klf6204@4ax.com...
> On Fri, 25 Apr 2003 19:19:45 +0000 (UTC), whayes@hfx.andara.com
> ("William Hayes") wrote:
>
> >Hello,
> >
> >The following is a slighly abbreviated quote from the Standard (3.5, item
6)
> >concerning the linkage granted identifiers declared extern at block
scope,
> >including an example and its comments on that example:
> >
> >"If there is a visible declaration of an entity with linkage having the
same
> >name and type, ignoring entities declared outside the innermost enclosing
> >namespace scope, the block scope declaraton declares that same entity and
> >receives the linkage of the previous declaration ... Otherwise, if no
> >matching entity is found, the block scope entity receives external
linkage.
> >
> >[Example:
> >
> > static void f();
> > static int i; // 1
> > void g() {
> > extern void f(); // internal linkage
> > int i; // 2: i has no linkage
> > {
> > extern void f(); // internal linkage
> > extern int i; // 3: external linkage
> > }
> > }
> >
> >There are three objects named i in this program. The object with
internal
> >linkage introduced by the declaration in global scope (line //1), the
object
> >with automatic storage duration and no linkage introduced by the
declaraion
> >on line //2, and the object with static storage duration and external
> >linkage introduced by the declaration on line //3.]"
> >
> >--end of quote--
> >
> >It seems to me that according to the text there should be only two
objects
> >named i. The declaration at //3 should declare the same entity defined
at
> >//1: the latter is visible, and has linkage (albeit internal), and is
> >therefore a match. My compiler (g++ 3.2) seems to see it that way, too.
>
> The local declaration of i at //2 hides the file-scope declaration at
> //1. If the declration at //1 were not present, the declaration at //3
> would refer to //1. But since //1 is not visible, the declaration at
> //3 refers to a global i in some other translation unit.
>
>
> ---
> Steve Clamage, stephen.clamage@sun.com
>
> ---
Thanks, that clears it up: the fact that the i declared at //2 has no
linkage does not (of course) affect its visibility, or its hiding of the i
declared at //1.
Your columns in C++ Report, by the way, are very much missed.
---------------
Bill Hayes
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: stephen.clamage@sun.com (Stephen Clamage)
Date: Mon, 28 Apr 2003 06:16:02 +0000 (UTC) Raw View
On Fri, 25 Apr 2003 19:19:45 +0000 (UTC), whayes@hfx.andara.com
("William Hayes") wrote:
>Hello,
>
>The following is a slighly abbreviated quote from the Standard (3.5, item 6)
>concerning the linkage granted identifiers declared extern at block scope,
>including an example and its comments on that example:
>
>"If there is a visible declaration of an entity with linkage having the same
>name and type, ignoring entities declared outside the innermost enclosing
>namespace scope, the block scope declaraton declares that same entity and
>receives the linkage of the previous declaration ... Otherwise, if no
>matching entity is found, the block scope entity receives external linkage.
>
>[Example:
>
> static void f();
> static int i; // 1
> void g() {
> extern void f(); // internal linkage
> int i; // 2: i has no linkage
> {
> extern void f(); // internal linkage
> extern int i; // 3: external linkage
> }
> }
>
>There are three objects named i in this program. The object with internal
>linkage introduced by the declaration in global scope (line //1), the object
>with automatic storage duration and no linkage introduced by the declaraion
>on line //2, and the object with static storage duration and external
>linkage introduced by the declaration on line //3.]"
>
>--end of quote--
>
>It seems to me that according to the text there should be only two objects
>named i. The declaration at //3 should declare the same entity defined at
>//1: the latter is visible, and has linkage (albeit internal), and is
>therefore a match. My compiler (g++ 3.2) seems to see it that way, too.
The local declaration of i at //2 hides the file-scope declaration at
//1. If the declration at //1 were not present, the declaration at //3
would refer to //1. But since //1 is not visible, the declaration at
//3 refers to a global i in some other translation unit.
---
Steve Clamage, stephen.clamage@sun.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: whayes@hfx.andara.com ("William Hayes")
Date: Fri, 25 Apr 2003 19:19:45 +0000 (UTC) Raw View
Hello,
The following is a slighly abbreviated quote from the Standard (3.5, item 6)
concerning the linkage granted identifiers declared extern at block scope,
including an example and its comments on that example:
"If there is a visible declaration of an entity with linkage having the same
name and type, ignoring entities declared outside the innermost enclosing
namespace scope, the block scope declaraton declares that same entity and
receives the linkage of the previous declaration ... Otherwise, if no
matching entity is found, the block scope entity receives external linkage.
[Example:
static void f();
static int i; // 1
void g() {
extern void f(); // internal linkage
int i; // 2: i has no linkage
{
extern void f(); // internal linkage
extern int i; // 3: external linkage
}
}
There are three objects named i in this program. The object with internal
linkage introduced by the declaration in global scope (line //1), the object
with automatic storage duration and no linkage introduced by the declaraion
on line //2, and the object with static storage duration and external
linkage introduced by the declaration on line //3.]"
--end of quote--
It seems to me that according to the text there should be only two objects
named i. The declaration at //3 should declare the same entity defined at
//1: the latter is visible, and has linkage (albeit internal), and is
therefore a match. My compiler (g++ 3.2) seems to see it that way, too.
Could anyone shed any light on this?
Thanks.
William Hayes
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]