title: Replace a string in a macro variable?
body: <p>I have a macro where I pass in an argument and use that define a new variable based on the name of the input:</p>
  
  <pre><code>#define DO_X(x) char _do_x_var_ ## x; /* other things */
  </code></pre>
  
  <p>The problem is if I pass in a struct variable, it breaks:</p>
  
  <pre><code>DO_X(some_struct-&gt;thing)
  </code></pre>
  
  <p>becomes:</p>
  
  <pre><code>char _do_x_var_some_struct-&gt;thing; /* other things */
  </code></pre>
  
  <p>EDIT: What I want it to evaluate to is:</p>
  
  <pre><code>char _do_x_var_some_struct__thing; /* other things */
  </code></pre>
  
  <p>(or any valid variable name containing something similar to the input)</p>
  
  <p>What I actually want is for these to work:</p>
  
  <pre><code>#define DO_X(x) for(char _do_x_var_ ## x; /*things*/)
  DO_X(x){
      DO_X(y) {
          /*things*/
      }
  }
  
  DO_X(object-&gt;x){
      DO_X(object-&gt;y) {
          /*things*/
      }
  }
  </code></pre>
  
  <p>but for these to fail:</p>
  
  <pre><code>#define DO_X(x) for(char _do_x_var_ ## x; /*things*/)
  DO_X(x){
      DO_X(x) { // &lt;-- multiple definition of _do_x_var_x
          /*things*/
      }
  }
  
  DO_X(object-&gt;x){
      DO_X(object-&gt;x) { // &lt;-- multiple definition of _do_x_var_object__x (or whatever)
          /*things*/
      }
  }
  </code></pre>
  
  <p>Is there some way to make this work? Maybe replacing <code>-&gt;</code> with <code>__</code> or something? I've found ways to concatenate, but not replace strings..</p>