Oracle® Solaris Studio 12.4: C User's Guide

Exit Print View

Updated: March 2015
 
 

2.11.27 weak

#pragma weak symbol1 [= symbol2]

This pragma defines a weak global symbol. It is used mainly when building libraries. The linker does not produce an error message if it is unable to resolve a weak symbol.

#pragma weak symbol

defines symbol to be a weak symbol. The linker does not produce an error message if it does not find a definition for symbol.

#pragma weak symbol1 = symbol2

defines symbol1 to be a weak symbol, which is an alias for the symbol symbol2. This form of the pragma can only be used in the same translation unit where symbol2 is defined, either in the source files or one of its included header files. Otherwise, a compilation error will result.

If your program calls but does not define symbol1 and symbol1 is a weak symbol in a library being linked, the linker uses the definition from that library. However, if your program defines its own version of symbol1, then the program’s definition is used and the weak global definition of symbol1 in the library is not used. If the program directly calls symbol2, the definition from the library is used. A duplicate definition of symbol2 causes an error.