From 0718a3222ad1cf0e9bf85947f6a32b106cdb2ee4 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 20 May 2010 17:27:45 +0200 Subject: started to get rid of funny casts in library test --- tests/library/test_loader.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'tests') 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 ); -- cgit v1.2.3-54-g00ecf