Guest User

Untitled

a guest
Nov 21st, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. ISO C forbids assignment between function pointer and 'void *' [-pedantic]
  2.  
  3. void *(*funcPtr)();
  4. funcPtr = GetPointer();
  5.  
  6. void *GetPointer();
  7.  
  8. #include <dlfcn.h>
  9.  
  10. int
  11. main(int argc, char *argv[])
  12. {
  13. ...
  14. void (*funcp)(void); /* Pointer to function with no arguments */
  15. ...
  16. *(void **) (&funcp) = dlsym(libHandle, argv[2]);
  17. }
  18.  
  19. warning: ISO C forbids passing argument 2 of ‘g_slist_append’ between function pointer and ‘void *’ [-pedantic]
  20.  
  21. typedef int (* func) (int);
  22.  
  23. int mult2(int x)
  24. {
  25. return x + x;
  26. }
  27.  
  28. int main(int argc, char *argv[])
  29. {
  30. GSList *functions = NULL;
  31. func f;
  32.  
  33. functions = g_slist_append(functions, mult2);
  34. f = (func *) functions->data;
  35. printf("%dn", f(10));
  36. return 0;
  37. }
  38.  
  39. struct funcstruct {
  40. int (* func) (int);
  41. };
  42.  
  43. int mult2(int x)
  44. {
  45. return x + x;
  46. }
  47.  
  48. int main(int argc, char *argv[])
  49. {
  50. GSList *functions = NULL;
  51. struct funcstruct p;
  52. p.func = mult2;
  53.  
  54. functions = g_slist_append(functions, &p);
  55. p = * (struct funcstruct *) functions->data;
  56. printf("%dn", p.func(10));
  57. return 0;
  58. }
  59.  
  60. #include <dlfcn.h>
  61.  
  62. /* Pointer to function with no arguments */
  63. typedef void (functor_t*)(void);
  64.  
  65. void load_symbol( functor_t* functor, void* dl_handle, const char* symbol_name ) {
  66. *(void**)functor = dlsym( dl_handle, symbol_name );
  67. }
  68.  
  69. int
  70. main(int argc, char *argv[])
  71. {
  72. // [...]
  73. functor_t funcp;
  74. // [...]
  75. load_symbol( &funcp, libHandle, argv[2]);
  76. }
Add Comment
Please, Sign In to add comment