From owner-freebsd-hackers@FreeBSD.ORG Thu May 1 15:16:40 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 59FB437B401; Thu, 1 May 2003 15:16:40 -0700 (PDT) Received: from fafoe.dyndns.org (chello212186121237.14.vie.surfer.at [212.186.121.237]) by mx1.FreeBSD.org (Postfix) with ESMTP id 96BF443F85; Thu, 1 May 2003 15:16:39 -0700 (PDT) (envelope-from stefan@fafoe.dyndns.org) Received: from wombat.fafoe (wombat.fafoe [192.168.2.102]) by fafoe.dyndns.org (Postfix) with ESMTP id 3A2BA3FC4; Fri, 2 May 2003 00:16:36 +0200 (CEST) Received: by wombat.fafoe (Postfix, from userid 1001) id 5483DD1; Fri, 2 May 2003 00:16:32 +0200 (CEST) Date: Fri, 2 May 2003 00:16:32 +0200 From: Stefan Farfeleder To: Mike Hunter Message-ID: <20030501221631.GB546@wombat.fafoe> Mail-Followup-To: Mike Hunter , Dag-Erling Smorgrav , "Jacques A. Vidrine" , hackers@FreeBSD.org References: <20030501150713.GA34992@madman.celabo.org> <20030501152022.GC568@wombat.fafoe> <20030501213418.GA42794@falcon.midgard.homeip.net> <20030501214326.GA10277@ack.Berkeley.EDU> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030501214326.GA10277@ack.Berkeley.EDU> User-Agent: Mutt/1.5.4i cc: "Jacques A. Vidrine" cc: hackers@FreeBSD.org cc: Dag-Erling Smorgrav Subject: Re: incorrect enum warning? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 May 2003 22:16:40 -0000 On Thu, May 01, 2003 at 02:43:26PM -0700, Mike Hunter wrote: > On May 01, "Erik Trulsson" wrote: > > > On Thu, May 01, 2003 at 11:03:40PM +0200, Dag-Erling Smorgrav wrote: > > > Stefan Farfeleder writes: > > > > Because 0x80000000 > INT_MAX on 32-Bit architectures, 0x80000000 has > > > > type unsigned. But enumeration constants always have type int, that's > > > > why you're getting this warning. > > > > > > but 0x80000000 == INT_MIN on 32-bit two's complement systems... > > > > No. 0x80000000 has type unsigned int (assuming 32-bit int) and is thus > > a large positive number. INT_MIN has type signed int and is a negative > > number. The fact that they happen to have the same representation does > > not mean they are the same thing. > > #include > #include > > int main () > { > printf("%d\n", (0x80000000 == INT_MIN)); > return 0; > } > > ./a.out > 1 > > Just pointing out that they do "==" each other, which is what was said. That is because the comparison is done in unsigned arithmetics due to the "usual arithmetic conversions". The negative int value INT_MIN is converted to unsigned int by adding UINT_MAX + 1 before the comparison is evaluated. Regards, Stefan Farfeleder