From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike Haertel Message-Id: <200107120627.f6C6RBh99881@ducky.net> To: 9fans@cse.psu.edu Subject: [9fans] compiler bug Date: Wed, 11 Jul 2001 23:27:11 -0700 Topicbox-Message-UUID: c6a4a0ae-eac9-11e9-9e20-41e7f4b1d025 Under pcc, the following program: #include #include int main() { printf("%d\n", (int) (0x80000000 >> 31)); exit(EXIT_SUCCESS); } prints -1. It should print 1. According to ANSI C (either version, take your pick: c89, section 3.1.3.2, or c99, section 6.4.4.1) hex and octal constants take on the first type in the list: int, unsigned int, long, unsigned long, etc. in which their value is representable. In this case, 0x80000000 is not a representable value of type int, but is representable as unsigned int, so it should have that type. This bit me today when some of the initializers of an "unsigned long long" array mysteriously got sign extended from 32 bits.