473,322 Members | 1,480 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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
4 3693
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

94
by: Gabriel Zachmann | last post by:
Is it correct to say that strong/weak typing does not make a difference if one does not use any pointers (or adress-taking operator)? More concretely, I am thinking particularly of Python vs C++....
2
by: Wenjie | last post by:
Hello, I read someone posted assertions that even the (public) member function is not static, there are probably only one copy of the code in the executable. Then except the...
2
by: festiv | last post by:
Hi there, I want to learn how the compiler is implementing the dynamic binding. where can i read about this subject (the hole process). thanks.
9
by: Neelesh Bodas | last post by:
Hi all, does C++ give a way to declare a specific symbol as a "weak symbol"? In 'C', one can use #pragma directive. Is this still a legal way in C++ ? Is there a (better?) alternative?
7
by: Søren Dreijer | last post by:
Hi, I have a mixed C#, managed C++ and unmanaged C++ project. The managed class calls a method which exists in an unmanaged singleton class. During the entire lifetime of the application, this...
2
by: Nelis Franken | last post by:
Good day. Thanks for the previous help on binding member functions to use as predicates for STL functions (original example applied to sort()). The technique to use Boost's bind() works well,...
3
by: John Nagle | last post by:
Are weak refs slower than strong refs? I've been considering making the "parent" links in BeautifulSoup into weak refs, so the trees will release immediately when they're no longer needed. In...
15
by: Tom Gur | last post by:
Hi, What is early/late binding ?
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.