From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11222 invoked by alias); 12 Mar 2004 22:37:23 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 11212 invoked from network); 12 Mar 2004 22:37:22 -0000 Received: from unknown (HELO mail-out3.apple.com) (17.254.13.22) by sources.redhat.com with SMTP; 12 Mar 2004 22:37:22 -0000 Received: from mailgate1.apple.com (a17-128-100-225.apple.com [17.128.100.225]) by mail-out3.apple.com (8.12.11/8.12.11) with ESMTP id i2CMbLw2001095 for ; Fri, 12 Mar 2004 14:37:21 -0800 (PST) Received: from relay3.apple.com (relay3.apple.com) by mailgate1.apple.com (Content Technologies SMTPRS 4.3.6) with ESMTP id ; Fri, 12 Mar 2004 14:37:21 -0800 Received: from [17.201.20.186] (gambrinus.apple.com [17.201.20.186]) by relay3.apple.com (8.12.11/8.12.11) with ESMTP id i2CMbJh8022918; Fri, 12 Mar 2004 22:37:19 GMT In-Reply-To: References: <87wu5pwyg7.fsf@aladdin.de> Mime-Version: 1.0 (Apple Message framework v612) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <7705E534-7475-11D8-8D44-000A95D7CD40@apple.com> Content-Transfer-Encoding: 7bit Cc: Dale Johannesen , Andreas Schwab , GCC List From: Dale Johannesen Subject: Re: signed/unsigned right shift Date: Fri, 12 Mar 2004 22:37:00 -0000 To: Christian Groessler X-SW-Source: 2004-03/txt/msg00594.txt.bz2 On Mar 12, 2004, at 2:24 PM, Andreas Schwab wrote: > Christian Groessler writes: >> I have the following program which takes 2 unsigned short values, >> multiplies them and shifts the result right. >> >> This right shift gives a value with 1s bits at the high end. > > This is correct. The promotion rules let unsigned short promote to > int, > since the latter can represent all values of the former. Correct, the multiplication is done as signed int. And it is implementation defined whether right shift of a negative signed int does sign fill or not. So both compilers are right; it is only your code that's wrong. C89 references: 3.3.7, 3.2.1.5, 3.2.1.1.