This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [C++] GCC tree linkage types
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: Chris Lattner <sabre at nondot dot org>
- Cc: Ian Lance Taylor <ian at wasabisystems dot com>, gcc at gcc dot gnu dot org
- Date: Fri, 7 Nov 2003 10:51:02 -0500
- Subject: Re: [C++] GCC tree linkage types
- References: <Pine.LNX.4.44.0311071003550.18499-100000@nondot.org>
On Fri, Nov 07, 2003 at 10:05:06AM -0600, Chris Lattner wrote:
>
> Ian Lance Taylor writes:
>
> > A weak undefined symbol is like an ordinary undefined symbol, except
> > that it is not an error if the symbol is never defined (and in that
> > case the symbol is implicitly defined with the value zero).
>
> What are weak undefined symbols used for? If they are referenced but
> never defined, how does the program link?
As Ian said, they will be implicitly defined to zero if no definition
is present.
extern int foo_func() __attribute__((weak));
...
if (foo_func != 0)
return foo_func ();
...
There are a number of uses for this. For instance, glibc uses it to
call pthread locking functions iff the threading library is available
at runtime.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer