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?


On Jul  8, 2004, Nicholas Nethercote <njn25@cam.ac.uk> wrote:

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

You're not mixing enums with ints.  According to the C standard, the
type of enumerators (as opposed to the enumerate types themselves)
*is* int.

>     void f ( int );

>     typedef enum { AA, BB, CC } T;

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

Given the enumerator type definition above, AA is just another way to
spell 1, and CC is just another way to spell 3.  Should we warn about
conversions between enumerate and integer types, we'd have to warn
for:

T y = CC;

void g(T);  g(AA);

I suppose you wouldn't want these warnings.

-- 
Alexandre Oliva             http://www.ic.unicamp.br/~oliva/
Red Hat Compiler Engineer   aoliva@{redhat.com, gcc.gnu.org}
Free Software Evangelist  oliva@{lsd.ic.unicamp.br, gnu.org}


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