Weak binding of member functions

Discussion in 'C++' started by Vinay, Jul 1, 2004.

  1. Vinay

    Vinay Guest

    Hello

    My question is regarding "weak external symbols". Consider the
    following eg.

    class test
    {
    public :
    int func1(void); {cout <<"func1";}
    int func2(void);
    }

    int test :: func2(void)
    {
    cout <<"func2";
    }

    I compiled this piece of code using the CC for PPC processor, version
    "cygnus-2.7.2-960126 egcs-971225". The readelf output shows that the
    func1 has weak binding and func2 has normal global binding. Please let
    me know why is the function whos implementation is with in the class
    definition has weak binding and the one with its implementatin outside
    the class definition has normal global binding.

    regards
    Vinay
     
    Vinay, Jul 1, 2004
    #1
    1. Advertising

  2. Vinay

    Russ Guest

    Possibly because the function within the class definition is seen as a
    candidate for inlining and the one whose definition lies outside the class
    definition is not.
    Not really familiar with the term weak binding but thats my best guess on
    whats happening.
     
    Russ, Jul 1, 2004
    #2
    1. Advertising

  3. Vinay

    JKop Guest

    Vinay posted:

    > Hello
    >
    > My question is regarding "weak external symbols". Consider the
    > following eg.
    >
    > class test
    > {
    > public :
    > int func1(void); {cout <<"func1";}


    Syntax error. Lose the semicolon.

    int func1() { cout << "func1"; }


    > int func2(void);
    > }
    >
    > int test :: func2(void)
    > {
    > cout <<"func2";
    > }
    >
    > I compiled this piece of code using the CC for PPC processor, version
    > "cygnus-2.7.2-960126 egcs-971225". The readelf output shows that the
    > func1 has weak binding and func2 has normal global binding. Please let
    > me know why is the function whos implementation is with in the class
    > definition has weak binding and the one with its implementatin outside
    > the class definition has normal global binding.
    >
    > regards
    > Vinay
     
    JKop, Jul 1, 2004
    #3
  4. Re: [OT] Weak binding of member functions

    Vinay wrote:
    > Hello
    >
    > My question is regarding "weak external symbols". Consider the
    > following eg.
    >
    > class test
    > {
    > public :
    > int func1(void); {cout <<"func1";}
    > int func2(void);
    > }
    >
    > int test :: func2(void)
    > {
    > cout <<"func2";
    > }
    >
    > I compiled this piece of code using the CC for PPC processor, version
    > "cygnus-2.7.2-960126 egcs-971225". The readelf output shows that the
    > func1 has weak binding and func2 has normal global binding. Please let
    > me know why is the function whos implementation is with in the class
    > definition has weak binding and the one with its implementatin outside
    > the class definition has normal global binding.
    > ...


    Because the first one is inline function. Inline functions can (and
    normally will) have multiple definitions in multiple translation units.
    If the compiler decides to generate a normal (non-inline) body for this
    function, it is more than likely that this body will be present in
    multiple object files. Without normal binding that would result in an
    error at linking stage. Weak binding directs the linker to choose one
    body and discard the others, no error reported.

    We had a relevant discussion a couple of days ago. See topic "Inlines
    with external linkage".

    BTW, this is a compiler-related question. It should be asked in a
    compiler-related newsgroup, not here.

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Jul 2, 2004
    #4
  5. Re: [OT] Weak binding of member functions

    Andrey Tarasevich wrote:
    > ...
    > If the compiler decides to generate a normal (non-inline) body for this
    > function, it is more than likely that this body will be present in
    > multiple object files. Without normal binding that would result in an

    ^^^^^^^^^^^^^^^^^^^^^^
    I meant "With normal binding ...".

    > error at linking stage. Weak binding directs the linker to choose one
    > body and discard the others, no error reported.


    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Jul 2, 2004
    #5
    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. Kuan Zhou
    Replies:
    1
    Views:
    5,202
    Paul Uiterlinden
    Jan 24, 2005
  2. Jordan
    Replies:
    2
    Views:
    2,573
    Jordan
    Feb 10, 2004
  3. Hicham Mouline
    Replies:
    0
    Views:
    454
    Hicham Mouline
    Apr 23, 2009
  4. Hicham Mouline
    Replies:
    1
    Views:
    441
    Michael DOUBEZ
    Apr 24, 2009
  5. Jens Thiele

    binding member functions

    Jens Thiele, Apr 13, 2004, in forum: Javascript
    Replies:
    5
    Views:
    142
    Jens Thiele
    Apr 15, 2004
Loading...

Share This Page