title: Macro to define a struct in C or C++
body: <p>Is it possible to define a struct with variable size of array. something like this:</p>
  
  <pre><code>#define CHAR_ARRAY(MAX_LENGTH) struct CHAR_ARRAY_#MAX_LENGTH{char data[MAX_LENGTH]; int length;};
  </code></pre>
  
  <p>so that with just the above macro, I could define different data types as follows. </p>
  
  <pre><code>struct Data{
  CHAR_ARRAY(4) a;
  CHAR_ARRAY(8) b;
  };
  </code></pre>
  
  <p>Due to special requirements of existing code, plain old type defined with "struct" is required, no use of std::array, vector, etc. in particular, pointer is not accepted as our legacy code has the requirement to be plain old type, so assign or copy can be easily handled. </p>