title: Problem definition of struct in Macro
body: <p>I'm working on macros in C, trying to simulate the objet behavior but using C and I'm having a problem with the definition of a variable defined from a struct in another struct in a macro. That's my code... it works:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define STACK_MAX_CAPACITY 10
  #define DECLARE_STACK(Type)                             \
      typedef struct MetaPile_##Type;                     \
                                                          \
      typedef struct Pile_##Type_t{                       \
          Type q[STACK_MAX_CAPACITY];                     \
          int pos;                                        \
      } Pile_##Type;                                      \
                                                          \
      typedef struct MetaPile_##Type_t{                   \
          void (* push) ( Pile_##Type* p, Type val );     \
          void (*init) (Pile_##Type* p);                  \
      } MetaPile_##Type;                                  \
                                                          \
      void init_##Type( Pile_##Type* p ){                 \
          p-&gt;pos = 0;                                     \
          int i;                                          \
          for(i=0; i&lt;STACK_MAX_CAPACITY; i++){            \
              p-&gt;q[i]=0;                                  \
          }                                               \
      }                                                   \
                                                          \
      void push_##Type( Pile_##Type* p, Type val ) {      \
          if(p-&gt;pos &lt; STACK_MAX_CAPACITY){                \
              p-&gt;q[p-&gt;pos]=val;                           \
              p-&gt;pos++;                                   \
          }                                               \
      }                                                   \
      MetaPile_##Type TheMetaPile_##Type;                 \
      void initTheMetaPile_##Type(){                      \
          TheMetaPile_##Type.init = &amp;init_##Type;         \
          TheMetaPile_##Type.push = &amp;push_##Type;         \
      }                                                   \
                                                          \
  
  DECLARE_STACK(int)
  
  int main(){
  
      int i;
  
      initTheMetaPile_int();
      Pile_int pi;
  
      TheMetaPile_int.init(&amp;pi);
  
      push_int(&amp;pi, 2);
      push_int(&amp;pi, 3);
      push_int(&amp;pi, 4);
      push_int(&amp;pi, 5);
      push_int(&amp;pi, 6);
  
      for(i=0; i&lt;STACK_MAX_CAPACITY; i++){
          printf("%d",pi.q[i]);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>The first structure define an array of a dinamic type thanks to the macro (Pile_##Type) that represents the attributs side of an objet, and another structure (MetaPile_##Type) that will manage the "methods" of the objet, via fonction pointers. The fonction init works as a constructor and initialises my "objet" pi. </p>
  
  <p>Now what I want is to have a reference in Pile_##Type of a variable of type MetaPile_##Type (called for exemple myClass) in order to be able to make pi->myClass->push and call the fonction push_int. But when I make:</p>
  
  <pre><code>typedef struct Pile_##Type_t{                       \
      Type q[STACK_MAX_CAPACITY];                     \
      int pos;                                        \
      MetaPile_##Type myClass;                        \
  } Pile_##Type;                                      \
  </code></pre>
  
  <p>I have a misunderstandable mistake...</p>
  
  <pre><code>D:\main.c|40|warning: useless keyword or type name in empty declaration|
  D:\main.c|40|error: syntax error before "MetaPile_int"|
  D:\main.c|40|warning: no semicolon at end of struct or union|
  D:\main.c|40|warning: type defaults to `int' in declaration of `Pile_int'|
  D:\main.c|40|warning: data definition has no type or storage class|
  D:\main.c|40|error: syntax error before '*' token|
  D:\main.c|40|error: syntax error before '*' token|
  D:\main.c|40|error: syntax error before '*' token|
  D:\main.c||In function `init_int':|
  D:\main.c|40|error: `p' undeclared (first use in this function)|
  D:\main.c|40|error: (Each undeclared identifier is reported only once|
  D:\main.c|40|error: for each function it appears in.)|
  D:\main.c|40|error: syntax error before '*' token|
  D:\main.c||In function `push_int':|
  D:\main.c|40|error: `p' undeclared (first use in this function)|
  D:\main.c|40|error: `val' undeclared (first use in this function)|
  D:\main.c||In function `main':|
  D:\main.c|47|error: syntax error before "pi"|
  D:\main.c|49|error: `pi' undeclared (first use in this function)|
  ||=== Build finished: 12 errors, 4 warnings ===|
  </code></pre>
  
  <p>I don't know what's worong with the defintion of myClass, I've used * also but the error persits. Thanks if somebody can help.</p>