title: Access struct members as if they are a single array?
body: <p>I have two structures, with values that should compute a pondered average, like this simplified version:</p>
  
  <pre><code>typedef struct
  {
    int v_move, v_read, v_suck, v_flush, v_nop, v_call;
  } values;
  
  typedef struct
  {
    int qtt_move, qtt_read, qtt_suck, qtd_flush, qtd_nop, qtt_call;
  } quantities;
  </code></pre>
  
  <p>And then I use them to calculate:</p>
  
  <pre><code>average = v_move*qtt_move + v_read*qtt_read + v_suck*qtt_suck + v_flush*qtd_flush + v_nop*qtd_nop + v_call*qtt_call;
  </code></pre>
  
  <p>Every now and them I need to include another variable. Now, for instance, I need to include <code>v_clean</code> and <code>qtt_clean</code>. I can't change the structures to arrays:</p>
  
  <pre><code>typedef struct
  {
      int v[6];
  } values;
  typedef struct
  {
      int qtt[6];
  } quantities;
  </code></pre>
  
  <p>That would simplify a lot my work, but they are part of an API that need the variable names to be clear.</p>
  
  <p>So, I'm looking for a way to access the members of that structures, maybe using <code>sizeof()</code>, so I can treat them as an array, but still keep the API unchangeable. It is guaranteed that all values are <code>int</code>, but I can't guarantee the size of an <code>int</code>.</p>
  
  <p>Writing the question came to my mind... Can a <code>union</code> do the job? Is there another clever way to automatize the task of adding another member?</p>
  
  <p>Thanks,
  Beco</p>