- /* Writing: cosine = (double (*)(double)) dlsym(handle, "cos");
- would seem more natural, but the C99 standard leaves
- casting from "void *" to a function pointer undefined.
- The assignment used below is the POSIX.1\-2003 (Technical
- Corrigendum 1) workaround; see the Rationale for the
- POSIX specification of dlsym(). */
+ cosine = (double (*)(double)) dlsym(handle, "cos");
+
+ /* 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.