title: Potential error by assuming memory layout of struct array passed to OpenGL
body: <p>I am following an OpenGL tutorial, and in it, what is being done to pass the mesh data to the video card is basically the following:</p>
  
  <pre><code>#include &lt;GL/glew.h&gt;
  #include &lt;glm/glm.hpp&gt;
  
  struct Vertex {
      ...
  private:
      glm::vec3 pos;
      glm::vec2 texCoord;
      glm::vec3 normal;
  };
  
  Mesh::Mesh(Vertex * vertices, unsigned int numVertices) {
      ...
      glBufferData(GL_ARRAY_BUFFER, numVertices * sizeof(vertices[0]), vertices, GL_STATIC_DRAW);
      ...
  }
  </code></pre>
  
  <p>However, I feel this could cause problems because of the assumption that the vertices will be laid out perfectly. Or is it guaranteed that the Vertex fields will be placed without padding and in that order? Also, I don't know what the layouts or sizes of the glm::vec* types are.</p>
  
  <p>Am I right to suspect that this could cause problems?</p>
  
  <p>What should be done instead?</p>
  
  <p>What can affect the layout of a struct?</p>