I have the following weakly linked declaration:
extern __attribute__((visibility ("default"))) Type* const symbolName __attribute__((weak_import));
The problem is, the symbol may or may not be defined, depending on the operating system.
So, when I use it func(symbolName);
, I get a signal 11 crash because I am attempting a dereference of null. I could ask if(&symbolName != NULL) { func(symbolName); }
, but that would require everyone using this symbol to remember asking this question, which is not optimal.
I am looking for some wizardly magic to conditionally modify or redeclare this symbol, only if unavailable, to have some default value which my func
would work with.
I understand this is an ugly solution and is not recommended. At this point, I just want to know if there is a way to do it, no matter how ugly or low-level.