467,912 Members | 1,380 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,912 developers. It's quick & easy.

Weak binding of member functions

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
Jul 22 '05 #1
  • viewed: 3460
Share:
4 Replies
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.
Jul 22 '05 #2
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

Jul 22 '05 #3
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

Jul 22 '05 #4
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

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

94 posts views Thread by Gabriel Zachmann | last post: by
2 posts views Thread by Wenjie | last post: by
2 posts views Thread by festiv | last post: by
9 posts views Thread by Neelesh Bodas | last post: by
7 posts views Thread by Søren Dreijer | last post: by
2 posts views Thread by Nelis Franken | last post: by
3 posts views Thread by John Nagle | last post: by
15 posts views Thread by Tom Gur | last post: by
7 posts views Thread by Immortal Nephi | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.