This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warning about int<-->enum conversions?



I'm seeing conflicting responses about the legality of these conversions:



On Thu, 8 Jul 2004, Giovanni Bajo wrote:


Does GCC have a flag that would make it give warnings if an enum
value is mixed up with an int?  Like this:

void f ( int );

typedef enum { AA, BB, CC } T;

    f (AA)           -- complain please
    int x = CC;      -- ditto

No, because this is a kind of integer promotion which is allowed by the standard ([conv.prom]/2), so there is nothing wrong about it. Converting the other way (int -> enum) is instead forbidden and should be rejected by GCC.


On Thu, 8 Jul 2004, Gabriel Dos Reis wrote:

In C, you can have both implicit conversions. C++ says that you can't go from int to enums implicitly

Who's right? Hmm... maybe you both are, I didn't actually specify whether this was C or C++ (it was meant to be C).


The reason I asked is that apprently Harbison & Steele (C: A Reference Manual) say:

  "In fact, some UNIX C compilers implement a weakly typed form of
  enumerations in which some conversions between enumerated types and
  integers are not permitted without casts"

N


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]