gcc: pragma: weak

6.62.11 Weak Pragmas; In order to be compatible with SRV4.
For compatibility with SVR4, GCC supports a set of #pragma directives for declaring symbols to be weak, and defining weak aliases.
#pragma weak symbol
This pragma declares symbol to be weak, as if the declaration had the attribute of the same name. The pragma may appear before or after the declaration of symbol. It is not an error for symbol to never be defined at all. A weak symbol is defined
. This pragma weak can appear before or after the symbol declaration, and there is no requirement for the position. In this way, even if this symbol is not defined, no error will be reported.
#pragma weak symbol1 = symbol2
This pragma declares symbol1 to be a weak alias of symbol2. It is an error if symbol2 is not defined in the current translation unit.; This means that symbol1 is a weak link to symbol2. An error occurs if symbol2 is not defined.

The scenario of this use is to define another function to call in a specific environment. When it is not necessary to execute in other cases. It is a special treatment. It doesn't matter if the compilation can't find this symbol. Of course, it is necessary to determine whether the symbol exists. It is to take the address symbol.

Guess you like

Origin blog.csdn.net/qq_36428903/article/details/131894915