Thread: internal/external linkage

  1. #1
    Registered User
    Join Date
    May 2008

    internal/external linkage


    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.


    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...


  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    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.

    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