aboutsummaryrefslogtreecommitdiff
path: root/dlfcn.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2019-07-25 20:34:46 +0200
committerPali Rohár <pali.rohar@gmail.com>2019-07-25 20:34:46 +0200
commit2bb5f487922aa908d27175c5a562d34f4c6197d9 (patch)
treed3daeb4830007336d5758022ebfe3baa6bbac7e8 /dlfcn.c
parent403b240f298d2a9f85c76299f6da8750263fd43b (diff)
downloaddlfcn-win32-2bb5f487922aa908d27175c5a562d34f4c6197d9.tar.gz
dlfcn-win32-2bb5f487922aa908d27175c5a562d34f4c6197d9.tar.bz2
dlfcn-win32-2bb5f487922aa908d27175c5a562d34f4c6197d9.zip
Fix gcc warning: ISO C forbids return between function pointer and void *
Instead of using compiler specific pragma to disable particular warning, rewrite code which cast from function pointer to data pointer according to POSIX dlopen() documentation. This also fix compile warning under MSVC. According to the ISO C standard, casting between function pointers and 'void *', as done above, produces undefined results. POSIX.1-2003 and POSIX.1-2008 accepted this state of affairs and proposed the following workaround: *(void **) (&cosine) = dlsym(handle, "cos"); This (clumsy) cast conforms with the ISO C standard and will avoid any compiler warnings.
Diffstat (limited to 'dlfcn.c')
-rw-r--r--dlfcn.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/dlfcn.c b/dlfcn.c
index 1815ae0..f8af91f 100644
--- a/dlfcn.c
+++ b/dlfcn.c
@@ -454,11 +454,7 @@ end:
454 save_err_str( name ); 454 save_err_str( name );
455 } 455 }
456 456
457 // warning C4054: 'type cast' : from function pointer 'FARPROC' to data pointer 'void *' 457 return *(void **) (&symbol);
458#ifdef _MSC_VER
459#pragma warning( suppress: 4054 )
460#endif
461 return (void*) symbol;
462} 458}
463 459
464char *dlerror( void ) 460char *dlerror( void )