Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ISO C forbids assignment between function pointer and 'void *' [-pedantic]
- void *(*funcPtr)();
- funcPtr = GetPointer();
- void *GetPointer();
- #include <dlfcn.h>
- int
- main(int argc, char *argv[])
- {
- ...
- void (*funcp)(void); /* Pointer to function with no arguments */
- ...
- *(void **) (&funcp) = dlsym(libHandle, argv[2]);
- }
- warning: ISO C forbids passing argument 2 of ‘g_slist_append’ between function pointer and ‘void *’ [-pedantic]
- typedef int (* func) (int);
- int mult2(int x)
- {
- return x + x;
- }
- int main(int argc, char *argv[])
- {
- GSList *functions = NULL;
- func f;
- functions = g_slist_append(functions, mult2);
- f = (func *) functions->data;
- printf("%dn", f(10));
- return 0;
- }
- struct funcstruct {
- int (* func) (int);
- };
- int mult2(int x)
- {
- return x + x;
- }
- int main(int argc, char *argv[])
- {
- GSList *functions = NULL;
- struct funcstruct p;
- p.func = mult2;
- functions = g_slist_append(functions, &p);
- p = * (struct funcstruct *) functions->data;
- printf("%dn", p.func(10));
- return 0;
- }
- #include <dlfcn.h>
- /* Pointer to function with no arguments */
- typedef void (functor_t*)(void);
- void load_symbol( functor_t* functor, void* dl_handle, const char* symbol_name ) {
- *(void**)functor = dlsym( dl_handle, symbol_name );
- }
- int
- main(int argc, char *argv[])
- {
- // [...]
- functor_t funcp;
- // [...]
- load_symbol( &funcp, libHandle, argv[2]);
- }
Add Comment
Please, Sign In to add comment