title: Enumerations within a struct - C vs C++
body: <p>I'm trying to use Enums within a struct, this compiles and works fine with <code>gcc</code>.
  But the same code when compiled with <code>g++</code> throws an error.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  struct foo
  {
      enum {MODE1, MODE2, MODE3} mode;
      enum {TYPE1, TYPE2} type;
  };
  void bar(struct foo* bar)
  {
      bar-&gt;mode = MODE1;
  }
  
  int main()
  {
      struct foo* foo = (struct foo*) malloc(sizeof(struct foo));
      bar(foo);
      printf("mode=%d\n",foo-&gt;mode);
  }
  </code></pre>
  
  <p>Output obtained with <code>gcc</code>:</p>
  
  <pre><code> $ gcc foo.c
   $ ./a.out
   mode=0
  </code></pre>
  
  <p>Output obtained with <code>g++</code>: </p>
  
  <pre><code> $ g++ foo.c
   foo.c: In function ‘void bar(foo*)’:
   foo.c:11: error: ‘MODE1’ was not declared in this scope
  </code></pre>