lua-users home
lua-l archive

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


> On Fri, Jan 08, 2010 at 11:16:58AM -0200, Roberto Ierusalimschy wrote:
> > That is why we never get rid of this warning. Any trick will only make
> > things worse. This is a Posix function used in the way it is intended to
> > be used. Too bad that C does not have proper support for it.
> 
> For aranha, I used something along the lines of:
> 
> void *symbol = dlsym(modhandle, funcname);
> if (symbol != NULL) {
>     lua_pushcclosure(L, *(lua_CFunction*)(void *)&symbol, 0);
>     lua_pushboolean(L, module_system_forked);
>     lua_pcall(L, 1, 0, 0);
> }
> 
> I'll admit that the casting chain isn't pretty; but it is reliable as far as I
> can tell.

Generally, this construction is not reliable:

  type1 var1 = f()
  type2 var2 = *(type2 *)&var1;

A compiler may detect that the function does not dereference any
pointer to objects of 'type1' and that 'var1' is never accessed,
and then optimize away the assignment to 'var1'.

-- Roberto