[PATCH v1] man/man3/dlopen.3: EXAMPLES: Simplify use of dlsym(3)

Alejandro Colomar <[email protected]>
Newsgroups org.kernel.vger.linux-man
Message-ID <508bb4972e4846eab32f11e924aec8e1c9132515.1778859636.git.alx@kernel.org>
The cast is entirely unnecessary.  Conversion from/to void* and function
pointers is implicit, and it's guaranteed by POSIX.  ISO C is irrelevant
here, because dlsym(3) requires POSIX, which provides the stronger
guarantees that we need.

And even before POSIX standardized these guarantees about void* and
function pointers, and system implementing dlsym(3) would have to
support them anyway, as otherwise dlsym(3) couldn't work at all.

Reported-by: Bruno Haible <[email protected]>
Suggested-by: Martin Uecker <[email protected]>
Cc: Walter Harms <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
---
 man/man3/dlopen.3 | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/man/man3/dlopen.3 b/man/man3/dlopen.3
index 482af099..d9be7502 100644
--- a/man/man3/dlopen.3
+++ b/man/man3/dlopen.3
@@ -567,23 +567,11 @@ .SS Program source
 \&
     dlerror();    /* Clear any existing error */
 \&
-    cosine = (typeof(double (double)) *) dlsym(handle, "cos");
+    cosine = dlsym(handle, "cos");
 \&
-    /* According to the ISO C standard, casting between function
-       pointers and \[aq]void *\[aq], as done above, produces undefined results.
-       POSIX.1\-2001 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.
-\&
-       The 2013 Technical Corrigendum 1 to POSIX.1\-2008 improved matters
-       by requiring that conforming implementations support casting
-       \[aq]void *\[aq] to a function pointer.  Nevertheless, some compilers
-       (e.g., gcc with the \[aq]\-pedantic\[aq] option) may complain about the
-       cast used in this program.  */
+    /* The 2013 Technical Corrigendum 1 to POSIX.1\-2008
+       required that conforming implementations support
+       converting \[aq]void *\[aq] to a function pointer.  */
 .\" http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html#tag_03_112_08
 .\" http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html#tag_16_96_07
 .\" http://austingroupbugs.net/view.php?id=74

Range-diff against v0:
-:  -------- > 1:  508bb497 man/man3/dlopen.3: EXAMPLES: Simplify use of dlsym(3)
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.