Topic: 3.5/6 example


Author: pavel@despammed.com ("Pavel Kuznetsov")
Date: Sun, 1 Dec 2002 18:41:20 +0000 (UTC)
Raw View
<<
3.5 Program and linkage [basic.link]

6 <...>

  [Example:
    static void f();
    static int i = 0;        //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
        }
    }
>>

It seems to me that this example is not consistent with the
passage 6 right above it. I believe that since "there is a
visible declaration of an entity with linkage having the same
name and type", namely static int i, defined at the point [1],
i at the point [3] should "declare that same entity and
receive the linkage of the previous declaration",
i.e. internal linkage. ((1))

But to my confusion example says that

<<
  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 declaration on line //2, and
  the object with static storage duration and external linkage
  introduced by the declaration on line //3. ]
>>

I would think that i [1] is not found at the point [3] because
it is hidden by the i defined at the point [2] ((2)). But all
of my compilers (VC++, Comeau 4.3.0.1 and Gcc 3.2) are in
agreement with interpretation ((1)). I.e. if I modify i right
after the point [3], the i defined at [1] is being modified...

Could anybody please clarify what interpretation is correct
((1)), ((2)), or another one, which I have missed?

--
Pavel

---
[ 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                       ]