title: Why do I get an error when directly comparing two enums?
body: <p>I have some code I'm porting to a new platform, and it started giving me an error about comparing two enumerators from two different enumerator-lists. I'm confused why it's giving me an error about this. </p>
  
  <p>The enumeration specificers section of the C spec (6.7.2.2) states:</p>
  
  <blockquote>
    <p>The identifiers in an enumerator list are declared as constants that have type int and
    may appear wherever such are permitted.<sup>127)</sup> An enumerator with = defines its
    enumeration constant as the value of the constant expression. If the first enumerator has
    no =, the value of its enumeration constant is 0.</p>
  </blockquote>
  
  <p>So I should be able to use enum members the same as int constants. In this small sample program:</p>
  
  <pre><code>enum first {
    a,
    b
  };
  
  enum second {
   c,
   d
  };
  
  int main(){
      enum first myf = a;
      enum second mys = c;
  
      if(myf == mys)
          printf("same value\n"); 
      return 0;
  }
  </code></pre>
  
  <p>When compiled with <code>gcc -Wall -Werror</code> I get the message:</p>
  
  <blockquote>
    <p>error: comparison between ‘enum first’ and ‘enum second’ [-Werror=enum-compare]</p>
  </blockquote>
  
  <p>I know that if I typecast both <code>myf</code> and <code>mys</code> as <code>int</code>s the compiler will be happy, just like I could set a couple of <code>int</code>s with the values from <code>myf</code> and <code>mys</code> and do the comparison; but why do I have to do <em>either</em> of these to get rid of the warning? Why does this warning exist in the first place? There must be some danger in doing this that I'm not seeing.</p>
  
  <hr>
  
  <p><strong>NOTE:</strong><br> I have read the gcc documentation on this enum-compare flag, but it doesn't say much of anything:</p>
  
  <blockquote>
    <p><b>-Wenum-compare</b><br>
    Warn about a comparison between values of different enumerated types. In C++ enumeral mismatches in conditional expressions are also diagnosed and the warning is enabled by default. In C this warning is enabled by -Wall. </p>
  </blockquote>