title: Return Different Data Types in C Function
body: <p>I am having the following situation:</p>
  
  <pre><code>void func ()
  {
      TEST_MACRO(....., ret_type)
      ..........
  }
  
  some_ptr* func2()
  {
      TEST_MACRO(....., ret_type)
      ..........
  }
  
  int func3()
  {
      TEST_MACRO(....., ret_type)
      ..........
  }
  </code></pre>
  
  <p>I am having 3 types of functions. In each function, I have to do a range check for the same variable (local variable).</p>
  
  <p>Depending upon the SUCCESS/FAILURE, I have to do the error handling in the Macro:</p>
  
  <pre><code>TEST_MACRO()
  {
   // FAILURE
   if (ret_val == VOID_TYPE)
   {
      return;
   }
   else if (ret_val == RET_PTR)
   {
      return NULL;
   }
   else /* ret_val = INT */
   {
      return FAILURE;
   }
  }
  </code></pre>
  
  <p>but ultimately, all the preprocessor code will land up into the same function.</p>
  
  <pre><code>Problem:
  
  int func3 ()
  {
    // Entire Error Handling
    if (..)
      return;
    else if(..)
      return NULL;
    else
      return FAILURE;
  }
  </code></pre>
  
  <p>This is NOT possible, but to implement the SAME FUNCTIONALITY, i.e. doing a range check on the SIMILAR local variable, using 3 different Macros (one for each return type) doesn't seem to be a clean way.</p>
  
  <p>Can somebody suggest me some good way of handling such a situation?</p>