Re: Weak binding of member functions

Sandra Loosemore <>
13 Jul 2004 22:05:04 -0400

          From comp.compilers

Related articles
Weak binding of member functions (2004-07-11)
Re: Weak binding of member functions (Sandra Loosemore) (2004-07-13)
| List of all articles for this month |

From: Sandra Loosemore <>
Newsgroups: comp.compilers
Date: 13 Jul 2004 22:05:04 -0400
Organization: Frogs On Ice,
References: 04-07-007
Keywords: linker
Posted-Date: 13 Jul 2004 22:05:04 EDT (Vinay) writes:

> 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.

C++ class declarations can appear in multiple compilation units.
(They typically go in .h files that are #included wherever the class
is referenced.) In your example, this means that the definition of
func1 can appear in multiple compilation units as well, so the
compiler has to emit it as a weak symbol to prevent the linker from
complaining about it as a multiply-defined symbol. OTOH, it's a real
error if there are multiple definitions of a non-inline function like
func2 present.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.