From: "Michael Kerrisk (man-pages)" <mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Mike Frysinger <vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>,
noname-CuI0ZDT4mYnsrOwW+9ziJQ@public.gmane.org
Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: "Writing" instead of "Warning" in dlopen(3) manpage
Date: Thu, 02 Jan 2014 14:46:59 +1300 [thread overview]
Message-ID: <52C4C513.7020509@gmail.com> (raw)
In-Reply-To: <201312311119.55754.vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
On 01/01/14 05:19, Mike Frysinger wrote:
> On Tuesday 31 December 2013 07:42:09 noname-CuI0ZDT4mYnsrOwW+9ziJQ@public.gmane.org wrote:
>> dlopen C code example contains following comment:
>>
>> /* Writing: cosine = (double (*)(double)) dlsym(handle, "cos");
>> ... */
>>
>> "Writing:" should be replaced with "Warning:".
>
> both are correct
>
> however, i wonder if the comment should be inverted. the latest POSIX spec
> requires that the natural cast work.
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html#tag_16_96_07
>
> Linux man pages document the normal Linux environment, and that means POSIX,
> not strict ISO C.
Thanks for your comments Mike. It's been at the back of my mind for a while now
to do something about this. I applied the patch below. Look okay to you?
Cheers,
Michael
diff --git a/man3/dlopen.3 b/man3/dlopen.3
index dd54120..47ca55f 100644
--- a/man3/dlopen.3
+++ b/man3/dlopen.3
@@ -466,15 +466,22 @@ main(int argc, char **argv)
dlerror(); /* Clear any existing error */
- /* 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");
- *(void **) (&cosine) = dlsym(handle, "cos");
-.\" But in fact "gcc -O2 -Wall" will complain about the preceding cast.
+ /* According to the C99 standard, casting 'void *' to a function pointer
+ as shown above is forbidden. POSIX.1-2003 and POSIX.2008 followed
+ C99's requirement, and proposed the following workaround:
+
+ *(void **) (&cosine) = dlsym(handle, "cos");
+
+ This (clumsy) cast conforms with C99 and will avoid any compiler
+ warnings.
+
+ The 2013 Technical Corrigendum to POSIX.1-2008 (a.k.a. POSIX.1-2013)
+ improved matters by requiring that conforming implementations support
+ casting 'void *' to a function pointer. Nevertheless, some compilers
+ (e.g., gcc with the '-pedantic' option) may complain about the cast
+ used in this program. */
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2014-01-02 1:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-31 12:42 "Writing" instead of "Warning" in dlopen(3) manpage noname-CuI0ZDT4mYnsrOwW+9ziJQ
2013-12-31 16:19 ` Mike Frysinger
[not found] ` <201312311119.55754.vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2014-01-02 1:46 ` Michael Kerrisk (man-pages) [this message]
[not found] ` <52C4C513.7020509-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-01-02 4:06 ` Mike Frysinger
[not found] ` <201401012306.40108.vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2014-01-02 9:33 ` Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkjYTw3_BGQKwVNyfs-rLmxgVMiH4hBy_gBm=9DpvSHnFA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-02 12:33 ` Mike Frysinger
[not found] ` <201401020733.11627.vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2014-01-02 19:20 ` Michael Kerrisk (man-pages)
[not found] ` <CAKgNAkjeDs21b36mULBF6VFQeoKeVOEDnRj=7GPTmchci-xDzA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-01-02 19:45 ` Mike Frysinger
[not found] ` <201401021445.17586.vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org>
2014-01-03 2:51 ` Michael Kerrisk (man-pages)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52C4C513.7020509@gmail.com \
--to=mtk.manpages-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-man-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=noname-CuI0ZDT4mYnsrOwW+9ziJQ@public.gmane.org \
--cc=vapier-aBrp7R+bbdUdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.