§3.5/6 in the C++11 Standard

Discussion in 'C++' started by Ayrosa, Apr 29, 2014.

  1. Ayrosa

    Ayrosa Guest

    §3.5/6

    The name of a function declared in block scope and the name of a variable declared by a block scope extern declaration have linkage. 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 declaration declares that same entity and receives the linkage of the previous declaration. If there is more than one such matching entity, the program is ill-formed. Otherwise, if no matching entity isfound, the block scope entity receives external linkage.[ 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
    }
    }

    There are three objects named i in this program. The object with internal linkage introduced by the declaration in global scope (line #1 ), the objectwith 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. --end example ]

    Consider the i object in line #3. Why does it have static storage duration and external linkage?
     
    Ayrosa, Apr 29, 2014
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.