From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20216 invoked by alias); 14 Mar 2004 18:09:33 -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 20208 invoked from network); 14 Mar 2004 18:09:32 -0000 Received: from unknown (HELO punt.aladdin.de) (195.124.73.2) by sources.redhat.com with SMTP; 14 Mar 2004 18:09:32 -0000 Received: by punt.aladdin.de; id TAA07354; Sun, 14 Mar 2004 19:12:04 +0100 Received: from caligula.groessler.org(10.23.1.2) by punt.aladdin.de via smap (3.2) id xma007349; Sun, 14 Mar 04 19:11:38 +0100 Received: from langhals (langhals.groessler.org [10.23.1.27]) by Caligula.groessler.org (8.12.10/8.12.9) with ESMTP id i2EI8k2n001731; Sun, 14 Mar 2004 19:08:47 +0100 (CET) (envelope-from cpg@aladdin.de) Received: from langhals ([127.0.0.1] helo=langhals.aladdin.de) by langhals with esmtp (Exim 3.36 #1 (Debian)) id 1B2a32-00015V-00; Sun, 14 Mar 2004 19:09:16 +0100 To: GCC List Subject: Re: signed/unsigned right shift From: Christian Groessler Date: Sun, 14 Mar 2004 18:09:00 -0000 Message-ID: <87vfl7s3lf.fsf@aladdin.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2004-03/txt/msg00628.txt.bz2 On 03/12/2004 02:34:46 PM PST Dale Johannesen wrote: > >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. Hmm, unfortunately I don't have the c89 standard document. Can somebody point me to the equvalent sections in c99? regards, chris