Thread: internal/external linkage

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    internal/external linkage

    Hi,

    Reviewing a linkage problem with a static data member of my class (problem on AIX), I started to doubt on its linkage type.


    # Internal linkage : identifiers can only be seen within a translation unit.
    # External linkage : identifiers can be seen (and referred to) in other translation units.

    If the identifier for a class has external linkage, then, in the implementation of that class, the identifiers for the following will also have external linkage:

    * A member function.
    * A static data member.

    (http://publib.boulder.ibm.com/infoce...ef/cplr082.htm)


    A named class has external linkage, of that I'm sure. The static data member in that class has therefore also external linkage, hasn't it?

    The standard says the following:


    ISO/IEC 14882:2003(E)
    9 Classes
    9.4.2 Static data members

    6 Static data members of a class in namespace scope have external linkage (3.5). A local class shall not
    have static data members.

    But what exactly is meant by the specification "in namespace scope"? Should a class with a static data member always be defined in a named namespace? That would seem strange to me...

    Thanks!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I don't think namespaces has anything to do with the linkage. The re-use of static for class member is more akin to static on local variables in functions than any of the other usages.

    And as you probably know, if you have a local static variable in a function, the scope of the function itself is not changed.

    static data members will be visible externally if the class itself is visible - namespace obviously comes into the visibility, but doesn't in itself define the external/internal linkage.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linkage question
    By DL1 in forum C++ Programming
    Replies: 6
    Last Post: 01-13-2009, 07:56 PM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  5. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM