lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 2 January 2015 at 12:35, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
> This code has been like this for more than 10 years. Why did you wait for
> 'rc3' to complain?  :-)

I only just tried adding -pedantic to MYCFLAGS

:P

>> To get around this, you need to use this hack: (as seem in dlsym manpage/POSIX):
>>
>>     double (*cosine)(double);
>>
>>     /* 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(). */
>>
>>    *(void **) (&cosine) = dlsym(handle, "cos");
>
> This hack is as undefined in C99 as ours,

The rationale from POSIX
(http://pubs.opengroup.org/onlinepubs/009695399/functions/dlsym.html):

> The ISO C standard does not require that pointers to functions can be cast back and forth to pointers to data. Indeed, the ISO C standard does not require that an object of type void * can hold a pointer to a function. Implementations supporting the XSI extension, however, do require that an object of type void * can hold a pointer to a function. The result of converting a pointer to a function into a pointer to another data type (except void *) is still undefined, however. Note that compilers conforming to the ISO C standard are required to generate a warning if a conversion from a void * pointer to a function pointer is attempted as in
>    fptr = (int (*)(int))dlsym(handle, "my_function");


> but we can change that if
> it removes the warning.

It does on my PC.