I have two modules A, B. A has a function f() that is globally acessible, i.e. the f() symbol is exported. B may want to call f() occasionally. But B should only call f() if module A is loaded. What is the best way for B to tell if A is loaded?
Part b to this question is there is a way to check if f() is exported?
I'm not sure which method is more effecient.
If B uses at least one of A's symbols, then by the time B is loaded, a module providing the required symbol(s) (in other words, a module like A) is also already loaded.
If the symbol were not available, you would not be able to load the module (B) requesting it.
I assume you load module B first, then optionally module A. My strategy would be to have A register a set of functions with B when A first initializes. B keeps a statically allocated function pointer (or a pointer to a struct full of function pointers) and provides exported functions to register and unregisters a handler. When A loads, it registers its function (or struct of functions) with B. When A unloads, it unregisters its functions.
It might go something like this:
B.h
B.c
A.c