Date: Tue, 25 Aug 1998 15:24:15 +0300 (IDT) From: Eli Zaretskii To: Mariano Alvarez Fernández cc: djgpp AT delorie DOT com Subject: Re: Possible bug in GCC In-Reply-To: <35E1A919.45F5@teleline.es> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Content-Transfer-Encoding: 8bit Precedence: bulk On Mon, 24 Aug 1998, Mariano Alvarez Fernández wrote: > #include > typedef enum { V1, V2, V3 } Tipo; > int main() > { > Tipo i; > i = -1; > if( i < 0 ) > puts( "Negative number" ); > else > puts( "Positive number" ); > } [snip] > I think it's a GCC bug because the K&R book (second ed.) say enum types > default to int (not unsigned as DJGPP does). No, this is a bug in your program. K&R book notwithstanding, you cannot assume anything about how enums are implemented, unless you specify this to the compiler (see below). The ANSI C standard explicitly says that the representation of enum is implementation-defined. Moreover, you are NOT supposed to assign any value to the enum variable except those in the enum definition. In your case, you can only assign V1, V2, or V3 to i; you cannot assign -1. Your example should be rewritten like this: typedef enum { INVALID = -1, V1, V2, V3 } Tipo; int main (void) { Tipo i; i = INVALID; if (i == INVALID) puts ("Invalid value"); else puts ("Valid value"); return 0; } Note that you cannot compare enum variables except with one of the values listed in the definition, or against another variable of the same enum. You cannot compare to arbitrary integer constants.