title: How to check the return value of a function pointer in dlsym?
body: <p>I am writing a library which will load dynamic library using dlopen and invoke the function given. </p>
  
  <p>My function pointer expect a function pointer which have return type as int.</p>
  
  <pre><code>typedef int (*function_handle)(int); 
  </code></pre>
  
  <p>Return type of one function is void in the shared object.</p>
  
  <pre><code> void some_function_ret_void(int b)
  </code></pre>
  
  <p>But dlsym not throws any error if i assign this pointer to fn.</p>
  
  <pre><code>typedef int (*function_handle)(int);
  function_handle fn;
  </code></pre>
  
  <p>Is there a way to check the return value of a function pointer got from dlsym ?</p>
  
  <pre><code>#include &lt;dlfcn.h&gt;
  #include &lt;stdio.h&gt;
  typedef int (*function_handle)(int);
  int main()
  {
    void* handle=dlopen("./libtest.so",RTLD_LAZY);
    function_handle fn;
    int retval =0;
    char *err;
    /**** How to check the return type of fn *********/
  
    fn=dlsym(handle, "some_function_ret_void");
    if ((err = dlerror()) != NULL) {
      printf("Could not invoke the handler %s",err);
      dlclose(handle);
      return 0;
    }
  
    /* 
      if(fn return type is void don't print anything)
  
      if(fn return type is char* , print the charecter) 
           free(str);
    */
  
    retval = fn(4);
    printf("%d",retval);  
    dlclose(handle);
    return 0;
  }
  </code></pre>
  
  <h1>in libtest.c (libtest.so)</h1>
  
  <pre><code>int some_function_ret_int( int a) {
       return a+10;
  }
  
  char* some_function_ret_str(int b) {
   //allocate memory for string and return;
  }
  
  void some_function_ret_void(int b) {
   //allocate memory for string and return;
  }
  </code></pre>