title: Variable Sized Struct C++
body: <p>Is this the best way to make a variable sized struct in C++? I don't want to use vector because the length doesn't change after initialization.</p>
  
  <pre><code>struct Packet
  {
      unsigned int bytelength;
      unsigned int data[];
  };
  
  Packet* CreatePacket(unsigned int length)
  {
      Packet *output = (Packet*) malloc((length+1)*sizeof(unsigned int));
      output-&gt;bytelength = length;
      return output;
  }
  </code></pre>
  
  <p>Edit: renamed variable names and changed code to be more correct.</p>