I want to check if A is linked with B or not, if linked i will use the
function from B else i will go for any other way.
Basically, you want to determine, at runtime, if a function of a
given name existed at link time?
As others have pointed out, you can't do this in anything resembling
portable code. There may be a system-specific way of doing this,
but you would have to check in a system-specific group for such info.
What I would recommend is a slight variation on your request. Rather
than linking with B or nothing, link with B or "alternate B", and
have both include a _pointer_ to the function, with "alternate B"
having a NULL pointer.[*] Have your A code check for a non-NULL
pointer, and call the function indirectly. As an alternative to
this method of explicitly linking with "alternate B", you may be
able to supply a library which is always linked with the code. If
you link with B, the pointer symbol will be resolved, and your
"alternate B" module from the library shouldn't be included. If
you link without B, your library module with the NULL pointer
should be linked it.
[*] Technically, I don't think a code pointer can be NULL, as a
code pointer may not be represented the same as a data pointer.
(Though I have to admit that I use such a construct in my code.)
You could always make your own definition for a null code
pointer, such as:
typedef int (*IntFunc)();
#define NULL_INT_FUNC ((IntFunc)0)
--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody |
www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net |
www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:
[email protected]>