Thread: linkage query

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    9

    linkage query

    hi guys
    could u put some light on my some queries relating to c.
    what is external and internal linkages.
    what is a translation unit.
    I wud be very thankful to u if give me some thought on above topics.

  2. #2
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    715
    Check this:
    http://msdn.microsoft.com/library/de...m/progs_20.asp

    A translation unit contains a sequence of one or more declarations. The Standard uses the term translation unit rather
    than source file because a single translation unit can be assembled from more than a single source file: A source file
    and the header files that are #included in it are a single translation unit.


    External Linkage
    A name that can be referred to from other translation units or from other scopes of the translation unit in which it was
    defined has external linkage. Following are some examples:
    Code:
    void g(int n) {} //g has external linkage
    int glob; //glob has external linkage
    extern const int E_MAX=1024; //E_MAX has external linkage
    namespace N
    {
    int num; //N::num has external linkage
    void func();//N::func has external linkage
    }
    class C {}; //the name C has external linkage
    Internal Linkage
    A name that can be referred to by names from other scopes in the translation unit in which it was declared, but not
    from other translation units, has internal linkage. Following are some examples:
    Code:
    static void func() {} //func has internal linkage
    union //members of a non-local anonymous union have internal linkage
    {
    int n;
    void *p;
    };
    const int MAX=1024; //non-extern const variables have internal linkage
    typedef int I; //typedefs have internal linkage
    Names With No Linkage
    A name that can only be referred to from the scope in which it is declared has no linkage. For example
    Code:
    void f()
    {
    int a; //a has no linkage
    class B {/**/}; //a local class has no linkage
    }
    Last edited by Micko; 09-11-2004 at 02:40 AM.

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