diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/library/test_loader.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c index b9bce9d..7e5fa28 100644 --- a/tests/library/test_loader.c +++ b/tests/library/test_loader.c @@ -26,6 +26,8 @@ int main( void ) { wolf_error_t error; char errbuf[512]; typedef int (*multiply_by_two_func)( int ); + union { multiply_by_two_func func; void *obj; } alias; + void *symbol; multiply_by_two_func func; int res = 0; @@ -37,8 +39,12 @@ int main( void ) { return EXIT_FAILURE; } - /* fetch a known symbol (multiply_by_two) */ - *(void **)(&func) = wolf_library_get( library, "multiply_by_two", &error ); + /* fetch a known function symbol (multiply_by_two), for the reasons why naive + * casting doesn't work, see: + * http://en.wikipedia.org/wiki/Dynamic_loading#cite_note-gcc-strict-aliasing-5 */ + symbol = wolf_library_get( library, "multiply_by_two", &error ); + alias.obj = symbol; + func = alias.func; /* call it */ res = func( 2 ); |