title: Flexible array member (c99) inside a structure
body: <p>I've being using this code a while now, and it works fine, but it gave me some headache to implement it. It uses Flexible Array Member (FAM) aka Struct Hack. Now that C99 has the possibility of using Variable Length Array (VLA), I wonder how can I take advantage in this piece?</p>
  
  <pre><code>typedef struct nO
  {
      int oper;              /* some operator */
      int nops;              /* number of args */
      struct nO *ptn[1];     /* expansible array &lt;=== HERE */
  } nodoOper;
  
  nodoOper *operator(int o, int n, ...)
  {
      va_list ap;
      nodoOper *tn;
      size_t tam;
      int i;
  
      tam = sizeof(nodoOper) + (n - 1) * sizeof(nodoOper *); /* &lt;=== AND HERE */
  
      if((tn=malloc(tam))==NULL)
          yyerror("Memory fault (cod. 4)");
  
      tn-&gt;oper = o;
      tn-&gt;nops = n;
      va_start(ap, n);
      for(i=0; i&lt;n; i++)
          tn-&gt;ptn[i] = va_arg(ap, nodoOper*);
      va_end(ap);
      return tn;
  }
  </code></pre>
  
  <p>(I've simplified the whole struct and code here, because it uses two more structs that is not important to the question, so maybe this example has bugs )</p>
  
  <p>Now, the struct definition is in a header file (.h), and the code create a syntax tree for a compiler. How can I change the array to use variable length?</p>
  
  <p>Thanks!
  Beco.</p>
  
  <p>Edited: rolling back the last editon to Flexible Array Member.</p>
  
  <p>2nd edition. Suppose I add inside the function this piece of code:</p>
  
  <pre><code>struct nOp
  {
      int oper;             /* some operator */
      int nops;             /* number of args */
      struct nOp *ptn[n];   /* Variable Length Array (VLA) */
  };
  struct nOp tnop;
  struct nOp *tn2;
  
  tn2 = &amp;tnop;
  return tn2;
  </code></pre>
  
  <p>First problem I see, I'm returning a pointer to a local variable. But beside that, is the way fruitful? 
  Thanks</p>