diff options
author | Andreas Baumann <abaumann@yahoo.com> | 2010-05-20 17:27:45 +0200 |
---|---|---|
committer | Andreas Baumann <abaumann@yahoo.com> | 2010-05-20 17:27:45 +0200 |
commit | 0718a3222ad1cf0e9bf85947f6a32b106cdb2ee4 (patch) | |
tree | 508f30622381199e364c62a0efbacd5e91741a94 /tests | |
parent | d5b4a2aefb2a8fae111c27092e114226db75b9b9 (diff) | |
download | wolfbones-0718a3222ad1cf0e9bf85947f6a32b106cdb2ee4.tar.gz wolfbones-0718a3222ad1cf0e9bf85947f6a32b106cdb2ee4.tar.bz2 |
started to get rid of funny casts in library test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/library/test_loader.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c index 6fd5d2e..15b5d12 100644 --- a/tests/library/test_loader.c +++ b/tests/library/test_loader.c @@ -27,12 +27,22 @@ #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; char errbuf[512]; typedef int (*multiply_by_two_func)( int ); - union { multiply_by_two_func func; void *obj; } alias; WOLF_LIBRARY_FUNCPTR symbol; multiply_by_two_func func; int res = 0; @@ -54,13 +64,8 @@ int main( void ) { fprintf( stderr, "Error %d fetching a function from the library: %s\n", error, wolf_library_errmsg( error, library, errbuf, 512 ) ); return EXIT_FAILURE; - } -#if !defined _WIN32 - alias.obj = symbol; - func = alias.func; -#else - func = (multiply_by_two_func)symbol; -#endif + } + WOLF_LIBRARY_FUNC_CAST( symbol, multiply_by_two_func, func ); /* call it */ res = func( 7 ); |