title: C method for iterating through a struct's members like an array?
body: <p>Let's say I have a vector class:</p>
  
  <pre><code>typedef struct vec3_s
  {
      float x, y, z;
  }
  vec3;
  </code></pre>
  
  <p>But, I would like to be able to iterate through it without converting it to an array of floats. While a cast is acceptable in this case, I'm curious to see if anything along the lines of C++ like functionality is doable in straight C. For example, in C++, since <code>std::vector&lt; T &gt;</code> has the subscript <code>[]</code> operator overloaded, I can pass the address of its first index to a function taking a <code>void*</code>.</p>
  
  <p>i.e.,</p>
  
  <pre><code>void do_something_with_pointer_to_mem( void* mem )
  {
      // do stuff
  }
  
  int main( void )
  {
      std::vector&lt; float &gt; v;
  
      // fill v with values here
  
      // pass to do_something_with_pointer_to_mem
  
      do_some_with_pointer_to_mem( &amp;v[ 0 ] );
  
      return;
  }
  </code></pre>
  
  <p>Another, more concrete example is when calls to <a href="http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml" rel="noreferrer">glBufferData(...)</a> are made in OpenGL (when using C++):</p>
  
  <p><code>glBufferData( GL_ARRAY_BUFFER, sizeof( somevector ), &amp;somevector[ 0 ], GL_STREAM_DRAW );</code></p>
  
  <p>So, is it possible to accomplish something similar in C using the subscript operator? If not, and I had to write a function (e.g., <code>float vec3_value_at( unsigned int i )</code>), would it make sense to just <code>static inline</code> it in the header file it's defined in?</p>