This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Warning about int<-->enum conversions?
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: Nicholas Nethercote <njn25 at cam dot ac dot uk>
- Cc: gcc at gcc dot gnu dot org
- Date: 09 Jul 2004 00:19:40 -0300
- Subject: Re: Warning about int<-->enum conversions?
- Organization: Red Hat Global Engineering Services Compiler Team
- References: <Pine.LNX.4.60.0407081331070.30153@hermes-1.csi.cam.ac.uk>
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}