title: C++ Preprocessor Stringize - Different between GCC and MSVC
body: <p>With the following example, the output is different between MSVC and GCC.  Can someone please point me in the right direction to understand why?</p>
  <pre><code>#define TO_STRING(...) #__VA_ARGS__
  #define QUOTE(...) TO_STRING(__VA_ARGS__)
  
  #define KEY1 &quot;Key1&quot;
  #define KEY2 &quot;Key2&quot;
  #define KEY3 &quot;Key3&quot;
  #define LEN1 32
  #define LEN2 32
  
  
  const char * cNVKeysMetaData = QUOTE(
  {
      &quot;Area1&quot;:[ 
          {
              &quot;key&quot;:KEY1,
              &quot;maxLength&quot;:LEN1,
              &quot;type&quot;:&quot;s&quot;,
              &quot;default&quot;:&quot;Hello&quot;
          },
  #if defined(TEST)
          {
              &quot;key&quot;:KEY2,
              &quot;maxLength&quot;:LEN2,
              &quot;type&quot;:&quot;s&quot;,
              &quot;default&quot;:&quot;invalid&quot;
          },
  #endif
          {
              &quot;key&quot;:KEY3,
              &quot;maxLength&quot;:64,
              &quot;type&quot;:&quot;s&quot;,
              &quot;default&quot;:&quot;invalid&quot;
          }
      ]
  }
  );
  
  #include &lt;iostream&gt;
  
  int main()
  {
      std::cout &lt;&lt; cNVKeysMetaData &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  <p>GCC Output:</p>
  <pre><code>{ &quot;Area1&quot;:[ { &quot;key&quot;:&quot;Key1&quot;, &quot;maxLength&quot;:32, &quot;type&quot;:&quot;s&quot;, &quot;default&quot;:&quot;Hello&quot; }, { &quot;key&quot;:&quot;Key3&quot;, &quot;maxLength&quot;:64, &quot;type&quot;:&quot;s&quot;, &quot;default&quot;:&quot;invalid&quot; } ] }
  </code></pre>
  <p>MSVC Output:</p>
  <pre><code>{ &quot;Area1&quot;:[ { &quot;key&quot;:&quot;Key1&quot;, &quot;maxLength&quot;:32, &quot;type&quot;:&quot;s&quot;, &quot;default&quot;:&quot;Hello&quot; }, #if defined(TEST) { &quot;key&quot;:&quot;Key2&quot;, &quot;maxLength&quot;:32, &quot;type&quot;:&quot;s&quot;, &quot;default&quot;:&quot;invalid&quot; }, #endif { &quot;key&quot;:&quot;Key3&quot;, &quot;maxLength&quot;:64, &quot;type&quot;:&quot;s&quot;, &quot;default&quot;:&quot;invalid&quot; } ] }
  </code></pre>
  <p>Note that MSVC does replace the macros KEY1 etc, but does not strip out the #if.  GCC does strip out the #if.</p>