#pragma
by definition not portable.
And weak binding is done during the connection (surprisingly enough). This allows a function (or any character, really) with the same signature to override another. This means that the strong will be preferred over the weak, but if not strong, the weak will be used.
Enable protective measures are performed by the compiler, not the linker, and they do not allow you to abandon the weak if the strong does not exist. You can simulate the same behavior if you control the source for both functions (via ifdef
-ing for one, ifndef
-ing for the other), but this is not always the case, and it more chooses between two powerful functions.
Weak linking allows you to do something like drop in your own malloc()/free()
for debugging purposes, while maintaining a link to the library that provides them.
source share