external linkage or internal?

Discussion in 'C++' started by al.cpwn@gmail.com, Mar 8, 2006.

  1. Guest

    do static and inline functions or members have internal linkage? I have
    been reading this newsgroup on google and found conflicting ideas. Can
    someone please help me understand why in some places inline may have
    external linkage while in others it has internal (from what I have read
    in comments by people). Are there any (other) places where linkage is
    ambiguous?
     
    , Mar 8, 2006
    #1
    1. Advertising

  2. * :
    > do static and inline functions or members have internal linkage? I have
    > been reading this newsgroup on google and found conflicting ideas. Can
    > someone please help me understand why in some places inline may have
    > external linkage while in others it has internal (from what I have read
    > in comments by people).


    // External linkage
    void a() {}

    // External linkage
    inline void b() {}

    // External linkage
    extern void c() {}

    // External linkage
    extern inline void d() {}

    // External linkage
    struct Foo1{ static void e(); };
    void Foo1::e() {}

    // External linkage
    struct Foo2{ static void f() {} };

    // External linkage
    struct Foo3{ void g(); }
    void Foo3::g() {}

    // External linkage
    struct Foo4{ void h() {} }

    // Internal linkage
    static void i() {}

    // Internal linkage
    static inline void j() {}

    void aFunction()
    {
    // No linkage.
    struct aStruct
    {
    ...
    };
    }

    Summing up, 'inline' is orthogonal to extern/internal linkage.

    However, 'inline' places an extra requirement, that of identical
    definitions in different translation units, on a function with extern
    linkage.


    > Are there any (other) places where linkage is ambiguous?


    I don't think there's any case of ambigious linkage.


    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Mar 8, 2006
    #2
    1. Advertising

  3. Guest

    Alf P. Steinbach wrote:
    > * :
    > > do static and inline functions or members have internal linkage? I have
    > > been reading this newsgroup on google and found conflicting ideas. Can
    > > someone please help me understand why in some places inline may have
    > > external linkage while in others it has internal (from what I have read
    > > in comments by people).

    >
    > // External linkage
    > void a() {}


    aren't members declared at file scope static implicitly? So even if
    void a() {} has external linkage, something like

    int x;

    should will be static and hence will have internal linkage.

    >
    > // External linkage
    > inline void b() {}


    Here I am confused. Lakos mentions that inline functions have internal
    linkage (1.1.2, pg 24). Why should the above example have external
    linkage then?

    >
    > // External linkage
    > extern void c() {}


    undertood

    >
    > // External linkage
    > extern inline void d() {}


    Again, why? What is the difference between extern inline void d() {}
    and inline void() d{} if they both have external linkage?

    >
    > // External linkage
    > struct Foo1{ static void e(); };
    > void Foo1::e() {}


    wow is there a quick way of determining or these have to be memorized?

    >
    > // External linkage
    > struct Foo2{ static void f() {} };


    well, here static void f() {} is inline as it is also defined where it
    is declared in the struct. Lakos mentions that this too should have
    internal linkage.

    >
    > // External linkage
    > struct Foo3{ void g(); }
    > void Foo3::g() {}
    >
    > // External linkage
    > struct Foo4{ void h() {} }
    >
    > // Internal linkage
    > static void i() {}
    >
    > // Internal linkage
    > static inline void j() {}
    >
    > void aFunction()
    > {
    > // No linkage.
    > struct aStruct
    > {
    > ...
    > };
    > }
    >
    > Summing up, 'inline' is orthogonal to extern/internal linkage.


    what does that mean?

    >
    > However, 'inline' places an extra requirement, that of identical
    > definitions in different translation units, on a function with extern
    > linkage.
    >
    >
    > > Are there any (other) places where linkage is ambiguous?

    >
    > I don't think there's any case of ambigious linkage.


    thanks, but I was only wondering how inline can have internal linkage
    or external
     
    , Mar 8, 2006
    #3
  4. Rolf Magnus Guest

    wrote:

    > Alf P. Steinbach wrote:
    >> * :
    >> > do static and inline functions or members have internal linkage? I have
    >> > been reading this newsgroup on google and found conflicting ideas. Can
    >> > someone please help me understand why in some places inline may have
    >> > external linkage while in others it has internal (from what I have read
    >> > in comments by people).

    >>
    >> // External linkage
    >> void a() {}

    >
    > aren't members declared at file scope static implicitly?


    This is not a member. And no.

    > So even if void a() {} has external linkage, something like
    >
    > int x;
    >
    > should will be static and hence will have internal linkage.


    Not unless it is also declared const.

    >> // External linkage
    >> inline void b() {}

    >
    > Here I am confused. Lakos mentions that inline functions have internal
    > linkage (1.1.2, pg 24).


    Who is Lakos?

    > Why should the above example have external linkage then?


    Because the C++ standard says so.

    >> // External linkage
    >> extern void c() {}

    >
    > undertood
    >
    >>
    >> // External linkage
    >> extern inline void d() {}

    >
    > Again, why? What is the difference between extern inline void d() {}
    > and inline void() d{} if they both have external linkage?


    Uhm, nothing?

    >> // External linkage
    >> struct Foo1{ static void e(); };
    >> void Foo1::e() {}

    >
    > wow is there a quick way of determining or these have to be memorized?
    >
    >>
    >> // External linkage
    >> struct Foo2{ static void f() {} };

    >
    > well, here static void f() {} is inline as it is also defined where it
    > is declared in the struct. Lakos mentions that this too should have
    > internal linkage.


    Then Lakos is wrong.

    >> // External linkage
    >> struct Foo3{ void g(); }
    >> void Foo3::g() {}
    >>
    >> // External linkage
    >> struct Foo4{ void h() {} }
    >>
    >> // Internal linkage
    >> static void i() {}
    >>
    >> // Internal linkage
    >> static inline void j() {}
    >>
    >> void aFunction()
    >> {
    >> // No linkage.
    >> struct aStruct
    >> {
    >> ...
    >> };
    >> }
    >>
    >> Summing up, 'inline' is orthogonal to extern/internal linkage.

    >
    > what does that mean?


    That they are separate concepts that don't have anything to do with each
    other.

    >> However, 'inline' places an extra requirement, that of identical
    >> definitions in different translation units, on a function with extern
    >> linkage.


    Actually, I would have said it frees you from the extra requirement of never
    defining an extern function more than once (aka one definition rule).
     
    Rolf Magnus, Mar 8, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. qazmlp
    Replies:
    9
    Views:
    1,035
    Ivan Vecerina
    Sep 3, 2003
  2. Replies:
    4
    Views:
    413
    David Thompson
    Sep 22, 2008
  3. Replies:
    1
    Views:
    609
    Michael DOUBEZ
    Sep 12, 2008
  4. puzzlecracker
    Replies:
    4
    Views:
    325
    Ron AF Greve
    Feb 7, 2009
  5. annalissa

    both internal and external linkage

    annalissa, Dec 29, 2009, in forum: C Programming
    Replies:
    2
    Views:
    1,089
    Kaz Kylheku
    Dec 30, 2009
Loading...

Share This Page