Weak symbol
From Wikipedia, the free encyclopedia
| This article does not cite any references or sources. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed. (December 2009) |
| This article is an orphan, as few or no other articles link to it. Please introduce links to this page from related articles; suggestions may be available. (December 2009) |
In computing, a weak symbol is a symbol definition in an object file or dynamic library that may be overridden by other symbol definitions. Its value will be zero if no definition is found by the loader.
Weak symbols are not mentioned by C or C++ language standards; as such, inserting them into code is not portable. Some compilers can create a weak symbol with a special #pragma, #pragma weak. However, the GNU Compiler Collection also supports a __attribute__((weak)) syntax as in the example below.
[edit] Example
Example written for the GNU Compiler Collection
Source of libfoo.so :
extern void foo(void) __attribute__((weak)); void fun(void) { if (foo) foo(); }
weak_test.c:
#include <stdio.h> void fun(void); void foo(void) { printf("Hello!\n"); } int main() { fun(); return 0; }
Compile with :
gcc weak_test.c -o weak_test -lfoo
[edit] External References
[edit] See also
| This computer science article is a stub. You can help Wikipedia by expanding it. |