cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: NSS and configure and pkg-config

From: Jamie Lokier <jamie_at_shareable.org>
Date: Mon, 7 Sep 2009 13:25:47 +0100

Kamil Dudka wrote:
> On Sunday 06 of September 2009 23:07:21 Daniel Stenberg wrote:
> > The argument seems to be that they don't want to specify the arguments as
> > that function pointer is used as a generic function pointer which can call
> > functions using different signatures. Similar to how a plain void * would
> > be used for generic data.
>
> Any idea how to solve this? I don't think void* could solve this as
> sizeof(void*) != sizeof (PRFuncPtr) on some obscure archs.

See also comp.lang.C FAQ question 4.13:

    [http://c-faq.com/ptrs/generic.html]

    void *'s are only guaranteed to hold object (i.e. data) pointers;
    it is not portable to convert a function pointer to type void
    *. (On some machines, function addresses can be very large, bigger
    than any data pointers.)

    It is guaranteed, however, that all function pointers can be
    interconverted, as long as they are converted back to an
    appropriate type before calling. Therefore, you can pick any
    function type (usually int (*)() or void (*)(), that is, pointer
    to function of unspecified arguments returning int or void) as a
    generic function pointer. When you need a place to hold object and
    function pointers interchangeably, the portable solution is to use
    a union of a void * and a generic function pointer (of whichever
    type you choose).

In other words, an empty argument list is *recommended* for this usage.

Modern toolchains seem to have recognised that people store function
pointers into "void *" pointers and "long" anyway, even though it's
not portable, so those archs which need function descriptors (like
FDPIC-ELF) make a function pointer a normal-size pointer to a function
descriptor object, instead of actually _being_ a function descriptor
object being passed around.

-- Jamie
Received on 2009-09-07