lua-users home
lua-l archive

Re: Warning with Lua 5.1.3 sources (gcc -pedantic)

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


>>>>> "AK" == Asko Kauppi <askok@dnainternet.net> writes:
 AK> There is a line in Lua sources, which gives warning with gcc '-
 AK> pedantic' compiler option.
 AK> Has anyone found a suitable solution to this?
 AK> lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
 >> loadlib.c: In function ‘ll_sym’:
 >> loadlib.c:77: warning: ISO C forbids conversion of object pointer to 
 AK> function pointer type
 AK> Did some googling, and:
 AK> http://www.webservertalk.com/message217658.html
 AK> Which does not really show a clear solution, does it?
C++ example is following, I guess it's not easy for plain C
template<class To, class From> inline To depun_ptr( From f ) {
#if defined( _MSC_VER )
 return (To)f;
#else
 union { From f; To t; } u;
 u.f = f;
 return u.t;
#endif
}
 // get rid of idiotic g++ warning
 template<class T> T symbol( const char *symbol_name ) const {
 return depun_ptr<T>( get_symbol( symbol_name ) );
 }
get_symbol is some wrapper for dlsym():
void *dynamic_library_t::get_symbol( const char *symbol_name ) const {
#if defined( _WIN32 )
 return (void*) GetProcAddress( lib_handle, symbol_name );
#elif defined( __hpux )
 void* symb;
 if( shl_findsym( (shl_t *)(&lib_handle),
		 symbol_name,
		 TYPE_UNDEFINED,
		 &symb ) != 0 )
 return 0;
 
 return symb;
#else
 return dlsym( lib_handle, symbol_name );
#endif
}
I hope the idea is clean
-- 
Yours sincerely, Eugeny.
Doctor Web, Ltd. http://www.drweb.com
+79119997425

AltStyle によって変換されたページ (->オリジナル) /