title: Why is this nested macro replacement failing?
body: <p>I am trying to apply the <a href="https://stackoverflow.com/questions/6635851/real-world-use-of-x-macros">X Macro</a> concept, in order to have the possibility to initialize all struct members to a custom default (invalid) value. I write the following code:</p>
  
  <pre><code>#define LIST_OF_STRUCT_MEMBERS_foo \
      X(a) \
      X(b) \
      X(c)
  
  #define X(name) int name;
  struct foo {
       LIST_OF_STRUCT_MEMBERS_foo
  };
  #undef X
  
  
  #define X(name) -1,
  static inline void foo_invalidate(struct foo* in) {
       *in = (struct foo){
       LIST_OF_STRUCT_MEMBERS_foo
       };
  }
  #undef X
  
  #define X(name) -1,
  #define foo_DEFAULT_VALUE  { LIST_OF_STRUCT_MEMBERS_foo }
  #undef X
  
  static struct foo test = foo_DEFAULT_VALUE;
  </code></pre>
  
  <p>However, when I run the preprocessor, the definition of <code>foo_DEFAULT_VALUE</code> fails to substitute the <code>X(name)</code> calls with <code>-1,</code></p>
  
  <p>Preprocessor output:</p>
  
  <pre><code>struct foo {
       int a; int b; int c;
  };
  
  static inline void foo_invalidate(struct foo* in) {
       *in = (struct foo){
       -1, -1, -1, /*Here the substitution worked nicely*/
       };
  }
  
  static struct foo test = { X(a) X(b) X(c) }; /*Why this substitution failed?*/
  </code></pre>
  
  <p>I thought <a href="https://stackoverflow.com/questions/7972785/can-a-c-macro-definition-refer-to-other-macros">C-macros could refer to other macros</a>. Do you know why that substitution fails? Is there any workaround?</p>
  
  <p>I could live with <code>foo_invalidate</code>, but I am reluctant to give up one step from having a value to be used directly at initialization.</p>