Re: Casting the return value of ...

Liste des GroupesRevenir à l c 
Sujet : Re: Casting the return value of ...
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.c
Date : 30. Mar 2024, 19:33:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86le5zipzo.fsf@linuxsc.com>
References : 1 2 3
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
scott@slp53.sl.home (Scott Lurndal) writes:

Kaz Kylheku <433-929-6894@kylheku.com> writes:
>
On 2024-03-28, Kenny McCormack <gazelle@shell.xmission.com> wrote:
>
But here's the thing.  Is the casting of the result of dlsym()
[to a function pointer type] necessary?
Isn't this the same as "casting the return value of malloc()", where you
>
Conversions between function pointers and data pointers are an
extension;  it is not well-defined behavior in ISO C.
>
I also seem to remember something like this, but I cannot trust this
documentation without a chapter-and-verse citation.
>
https://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html
>
Assuming it is true, there you have it;  if you're on POSIX, the compiler
is required to have the extension and it is connected to casting,
in which case the cast is required.
>
I've used this form for the last two decades, with gcc, with no
issues:
>
/**
 * Each shared object that simulates a Data Link Processor (DLP), will
 * contain a single namespace-scope function <b>get_dlp</b> which constructs
 * a DLP object of the specified type (for example, a #c_uniline_dlp,
 * #c_card_reader_dlp, et alia).   <b>get_dlp</b> returns the constructed
 * object as a #c_dlp object to the #channel function, which is then used
 * by the I/O subsystem to request services of the DLP at the MLI level.
 */
typedef c_dlp* (*get_dlp_t)(const char *, uint64_t, c_logger *);
...
    get_dlp_t   sym;
...
>
    sym = (get_dlp_t)dlsym(handle, "get_dlp");
    if (sym == NULL) {
        lp->log("Invalid DLP shared object format: %s\n", dlerror());
        unregister_handle(channel);
        dlclose(handle);
        return 1;
    }
>
>
I think there was a time in the development of GCC when there was
a warning even with the cast.  I don't think it's enabled by default
now?
>
We compile with -Wall -Werror and have never seen any warnings related to
casting the result of dlsym(), and we build with GCC[4..13].

Do you use -pedantic?  Compiling with -pedantic using gcc 8.4.0
gives a warning diagnostic (and a fatal error if -pedantic-errors
is specified in place of -pedantic).

Date Sujet#  Auteur
28 Mar 24 * Casting the return value of ...31Kenny McCormack
28 Mar 24 +* Re: Casting the return value of ...27Kaz Kylheku
28 Mar 24 i+* Re: Casting the return value of ...20Keith Thompson
28 Mar 24 ii`* Re: Casting the return value of ...19bart
28 Mar 24 ii +* Re: Casting the return value of ...12Keith Thompson
28 Mar 24 ii i+- Re: Casting the return value of ...1Chris M. Thomasson
28 Mar 24 ii i+* Re: Casting the return value of ...8Kaz Kylheku
29 Mar 24 ii ii+* Re: Casting the return value of ...5Kaz Kylheku
29 Mar 24 ii iii`* Re: Casting the return value of ...4Kaz Kylheku
29 Mar 24 ii iii `* Re: Casting the return value of ...3Michael S
29 Mar 24 ii iii  `* gcc Bugzilla search (was: Casting the return value of ...)2Michael S
29 Mar 24 ii iii   `- Re: gcc Bugzilla search1David Brown
29 Mar 24 ii ii+- Re: Casting the return value of ...1Keith Thompson
8 Jun 24 ii ii`- Re: Casting the return value of ...1Tim Rentsch
29 Mar 24 ii i`* Re: Casting the return value of ...2David Brown
30 Mar 24 ii i `- Re: Casting the return value of ...1Chris M. Thomasson
29 Mar 24 ii `* Re: Casting the return value of ...6David Brown
29 Mar 24 ii  `* Re: Casting the return value of ...5bart
29 Mar 24 ii   +- Re: Casting the return value of ...1David Brown
30 Mar 24 ii   `* Re: Casting the return value of ...3Tim Rentsch
30 Mar 24 ii    `* Re: Casting the return value of ...2bart
9 Apr 24 ii     `- Re: Casting the return value of ...1Tim Rentsch
30 Mar 24 i`* Re: Casting the return value of ...6Tim Rentsch
31 Mar 24 i +* Re: Casting the return value of ...3Lawrence D'Oliveiro
31 Mar 24 i i+- Re: Casting the return value of ...1David Brown
31 Mar 24 i i`- Re: Casting the return value of ...1Chris M. Thomasson
9 Apr 24 i `* Re: Casting the return value of ...2Tim Rentsch
9 Apr 24 i  `- Re: Casting the return value of ...1David Brown
29 Mar 24 +* Re: Casting the return value of ...2Andrey Tarasevich
29 Mar 24 i`- Re: Casting the return value of ...1Keith Thompson
30 Mar 24 `- Re: Casting the return value of ...1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal