title: Logging for different data types in C
body: <p>I'm writing some <code>C</code> code for a data logging type function.  Get value from variable, perform simple operation, and shove data into another variable.</p>
  
  <p>The key here, is accommodating so many different data types and operations on the data.  I tried using void pointers to all the different variables.  I then call the same function for each.</p>
  
  <p>Take a glance at the function.  You’ll see I’m rewriting the code over and over for each different data type.</p>
  
  <pre><code>    /***********************************************************/
      static void GenData(USHORT data_type,
                           USHORT operation,
                           void *var_p,
                           void *data_p)
      /***********************************************************/
     {
        switch (data_type)
        {
        case (DATA_INT):
          switch (operation) {
          case (OP_ONE_SHOT):
            *(int*)data_p = *(int*)var_p;
            break;
          case (OP_COUNTER):
            *(int*)data_p += 1;
            break;
          case (OP_CURR_TIME):
            *(int*)data_p = (int)sytime;
          case (OP_ELAPSED_TIME):
            *(int*)data_p += delta_tick_time;
            break;
          case (OP_MIN):
            if (*(int*)data_p &gt; *(int*)var_p) {
              *(int*)data_p = *(int*)var_p;
            }
            break;
          case (OP_MAX):
            if (*(int*)data_p &lt; *(int*)var_p) {
              *(int*)data_p = *(int*)var_p;
            }
            break;
          case (OP_ADD_ITSELF):
            *(int*)data_p += *(int*)data_p;
            break;
          default:
            break;
          }
          break;
  
        case (DATA_BYTE):
          switch (operation) {
          case (OP_ONE_SHOT):
            *(BYTE*)data_p = *(BYTE*)var_p;
            break;
          case (OP_COUNTER):
            *(BYTE*)data_p += 1;
            break;
          ...
          ...
  
        case (DATA_SHORT):
          ...and so on...
      }
  </code></pre>
  
  <p>Arithmetic on a void pointer in <code>C</code> isn't valid.  I'm not sure that means that I can't make this function better.  Is there a way I can write this so I don't have to rewrite the "mathy" parts over and over?</p>
  
  <p>As always, thank you for your time and efforts to help.</p>