I just opened the #pragma weak
in GCC:
6.57.9 Weak Pragmatists
For compatibility with SVR4, GCC supports the #pragma set of directives for declaring weak characters and defining weak aliases.
#pragma weak symbol
This pragma declares the character weak, as if the ad has an attribute with the same name. A pragma may appear before or after the declaration of a symbol. This is not a mistake for a character that can never be defined at all.
#pragma weak symbol1 = symbol2
This pragma declares character1 a weak alias for character2. This is an error if character2 is not defined in the current translation block.
http://gcc.gnu.org/onlinedocs/gcc/Weak-Pragmas.html
Although GCC developers generally dislike #pragma
and are encouraged to use __attribute__
instead for all sorts of things that might be pragmas, I tend to believe that #pragma weak
may actually be superior to an attribute-based approach that looks So:
extern __typeof(old_name) new_name __attribute__(weak, alias("old_name"))
Besides the ugliness requiring __typeof
(or requiring you to clearly know the type and spell, even if it is really a complex type of function), the biggest problem with the attribute based approach is that "old_name"
should be passed to gcc as a string for inserts literally into the generated assembly. This is problematic because different systems have different characteristics for changing the name (the most popular is the underscore prefix for all C character names or does nothing at all) and pass the correct string to the alias
attribute, you need to know which one you are creating, which is not really knowledge , which belongs to the application-level library, where weak aliases can be useful.
The syntax #pragma weak new_name = old_name
seems to avoid this problem by handling both names at the compiler level, where t can mutilate them properly if I am not mistaken.
So, with all the preliminary results, my current questions are: Am I mistaken about #pragma weak
that has this "portability" advantage? and Do all modern compilers on Unix-like systems (gcc, pcc, tinycc, icc, llvm / clang, etc.) still support the traditional SVR4 #pragma weak
?
I know the following similar question, but this is not like that, and the answers to not satisfactorily affect my question:
How tolerable is weak communication? #pragma weak my_symbol