From owner-freebsd-chat@FreeBSD.ORG Wed Feb 13 10:46:45 2008 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0213116A420 for ; Wed, 13 Feb 2008 10:46:45 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id BBF2C13C442 for ; Wed, 13 Feb 2008 10:46:44 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id 54397208C; Wed, 13 Feb 2008 11:46:39 +0100 (CET) X-Spam-Tests: AWL X-Spam-Learn: disabled X-Spam-Score: -0.3/3.0 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on tim.des.no Received: from ds4.des.no (des.no [80.203.243.180]) by smtp.des.no (Postfix) with ESMTP id D02E12083; Wed, 13 Feb 2008 11:46:38 +0100 (CET) Received: by ds4.des.no (Postfix, from userid 1001) id B8165844A3; Wed, 13 Feb 2008 11:46:38 +0100 (CET) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: deeptech71@gmail.com References: <47B24480.9020001@gmail.com> Date: Wed, 13 Feb 2008 11:46:38 +0100 In-Reply-To: <47B24480.9020001@gmail.com> (deeptech's message of "Wed\, 13 Feb 2008 02\:14\:40 +0100") Message-ID: <86abm56smp.fsf@ds4.des.no> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.1 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: freebsd-chat@freebsd.org Subject: Re: bits wrap when leftshifting non-constant amounts X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Feb 2008 10:46:45 -0000 deeptech71@gmail.com writes: > My gcc 3.4.6 behaves weirdly when left shifting, and I couldn't find > any info on this. [...] It is very clear in ISO/IEC 9899:1999 =C2=A76.5.7: 3 The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. It the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behaviour is undefined. In other words, the result can be anything at all, and is not even required to be consistent from one evaluation to the next. In fact, gcc is free to wipe your hard drive, shoot your dog and burn down your house for all the standard cares; which I guess is a roundabout way of saying "don't do that". DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no