title: Any workaround to self-referential macros in C? I'd like to append to a macro
body: <p>I have a file that uses a <code>FLAGS</code> macro from an include that I do not control. What is in <code>FLAGS</code> is not consistent. Occasionally I need to change <code>FLAGS</code> to add a flag to it. Now I know I can't do <code>#define FLAGS FLAGS|MY_FLAG</code>, but I thought if I stored <code>FLAGS</code> in a temporary variable that I could then undefine it and redefine it using the temporary and my flag. For example:</p>
  
  <pre><code>// Assume this next line is what's in the include file
  #define FLAGS   (1|2|4)
  
  // The rest of this is source, assume compile with -DMOD
  #ifdef MOD
  #define TEMP (FLAGS|8)
  #undef FLAGS
  #define FLAGS TEMP
  #endif
  
  int main()
  {
  printf("0x%x\n", FLAGS);
  }
  </code></pre>
  
  <p>And if <code>MOD</code> is defined the error is <code>error: 'FLAGS' was not declared in this scope</code>. I know that I can change all the actual C code that uses <code>FLAGS</code> to instead use <code>FLAGS|MY_FLAG</code> but I was hoping to modify the macro rather than all the code.</p>