diff options
-rw-r--r-- | include/wolf/library/loader.h | 16 | ||||
-rw-r--r-- | tests/library/test_loader.c | 11 |
2 files changed, 16 insertions, 11 deletions
diff --git a/include/wolf/library/loader.h b/include/wolf/library/loader.h index 11d5741..19979af 100644 --- a/include/wolf/library/loader.h +++ b/include/wolf/library/loader.h @@ -54,6 +54,22 @@ typedef struct wolf_library_t *wolf_library_p; #define WOLF_LIBRARY_FUNCPTR void * #endif +/* @brief casts a library symbol to a function pointer of a given type. + * + * Reason: conversion from void * to function pointer is illegal by ISO-99 + * (though it works actually on Posix) + */ +#if defined _WIN32 +#define WOLF_LIBRARY_FUNC_CAST( symbol__, func_t__, func__ ) func__ = (func_t__)symbol__ +#else +#define WOLF_LIBRARY_FUNC_CAST( symbol__, func_t__, func__ ) \ + { \ + union { func_t__ f__; void *s__; } alias__; \ + alias__.s__ = symbol__; \ + func__ = alias__.f__; \ + } +#endif + /** * Loads a shared library. * diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c index 15b5d12..ddcdbc5 100644 --- a/tests/library/test_loader.c +++ b/tests/library/test_loader.c @@ -27,17 +27,6 @@ #define LIBRARY_NAME "./testlib.so.0.0.0" #endif -#if defined _WIN32 -#define WOLF_LIBRARY_FUNC_CAST( symbol__, func_t__, func__ ) func__ = (func_t__)symbol__ -#else -#define WOLF_LIBRARY_FUNC_CAST( symbol__, func_t__, func__ ) \ - { \ - union { func_t__ f__; void *s__ } alias__; \ - alias__.s__ = symbol__; \ - func__ = alias__.f__; \ - } -#endif - int main( void ) { wolf_library_p library; wolf_error_t error; |