ISO C Void * and Function Pointers

后端 未结 3 1979
情话喂你
情话喂你 2021-02-04 02:21

While following some tutorials and reading about function pointers I learned that evidently assigning a void pointer to a function pointer in ISO C is undefined, is there any wa

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 03:21

    In tlpi-book I found this trick very interesting:

    #include 
    
    int
    main(int argc, char *argv[])
    {
        ...
        void (*funcp)(void);        /* Pointer to function with no arguments */
        ...
        *(void **) (&funcp) = dlsym(libHandle, argv[2]);
    }
    

提交回复
热议问题