Weak symbols are not mentioned by the C or C++ language standards; as such, inserting them into code is not very portable.
[2][3][4][5][6][7] The nm command identifies weak symbols in object files, libraries, and executables.
Weak symbols can be used as a mechanism to provide default implementations of functions that can be replaced by more specialized (e.g. optimized) ones at link-time.
Depending on the library ordering on the link command line (i.e. -lfoo -lbar) the dynamic linker uses the weak f from libfoo.so although a strong version is available at runtime.
[7] An alternative to the above construct is using a system API to check if func is defined (e.g. dlsym with RTLD_DEFAULT).
The above check may also fail for other reasons, e.g. when func contains an elf jump table entry.
Using it on a function definition may yield unexpected results, depending on the compiler and optimization level.
The generic part of kernel (called genunix) specifies weak functions that are overridden in platform specific part of the kernel (called unix) such as Virtual memory routines.
C preprocessor (CPP) conditional constructs can also be used to switch between different versions of a symbol.