How tolerable is weak communication? #pragma weak my_symbol

How portable is a weak compound?

#pragma weak my_symbol 

I see this question: how-to-make-weak-linking-work-with-gcc discusses how to make it work. But is there a good way to do this so that gcc is not required?

What is the difference between weak binding and declartion protection of C # ifdef?

 #ifndef my_weak_fn void my_weak_fn(){/* Do nothing */ return;} #endif 
+2
source share
1 answer

#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.

+12
source

Source: https://habr.com/ru/post/909239/


All Articles