title: C vs C++ compilation incompatibility - does not name a type
body: <p>I am trying to use a supplier's library in combination with my C++ application. The library is largely based on C, which is normally not a problem with the <code>extern "C"</code> option, but I ran into an issue that the C++ compiler does not accept. </p>
  
  <p>I simplified my code into the following example files. header.h represents a header from the suppier library, main.c/cpp are my own files. My real application is a C++ application, so I want to get it to work with main.cpp. </p>
  
  <p>header.h (note the line <code>u64 u64;</code>):</p>
  
  <pre><code>#ifndef HEADER_H
  #define HEADER_H
  
  #include &lt;stdint.h&gt;
  
  typedef uint64_t u64;
  
  union teststruct {
      u64 u64;
      struct {
          u64 x:32;
          u64 y:32;
      } s;
  };
  
  #endif
  </code></pre>
  
  <p>main.c:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "header.h"
  
  int main() {
      union teststruct a;
      a.u64=5;
      printf("%x\n", a.u64);
  
      return 0;
  }
  </code></pre>
  
  <p>main.cpp (same as main.c but with an extra <code>extern "C"</code> statement): </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  extern "C" {
  #include "header.h"
  }
  
  int main() {
      union teststruct a;
      a.u64=5;
      printf("%x\n", a.u64);
  
      return 0;
  }
  </code></pre>
  
  <p>Compiling main.c using the line</p>
  
  <pre><code>gcc -o test main.c
  </code></pre>
  
  <p>compiles without problems. However, compiling the C++ version using the g++ compiler with the command </p>
  
  <pre><code>g++ -o test main.cpp
  </code></pre>
  
  <p>gives the following compiler errors:</p>
  
  <pre><code>In file included from main.cpp:12:0:
  header.h:11:9: error: ‘u64’ does not name a type
           u64 x:32;
           ^
  header.h:12:9: error: ‘u64’ does not name a type
           u64 y:32;
           ^
  </code></pre>
  
  <p>The issue is that the supplier used the same name (u64) for both the type and the variable name, which seems like a bad idea to begin with, but gcc apparently accepts it. I do not want to change the library (i.e. header.h) as it is very large,this occurs a lot in the code, and I occasionally get updates for it. Is there a way to make g++ accept this combination, or a way to modify main.cpp to make it compile <em>without</em> changing header.h?</p>