From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22986 invoked by alias); 14 Jul 2005 01:10:24 -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 22947 invoked by uid 22791); 14 Jul 2005 01:10:15 -0000 Received: from sccrmhc12.comcast.net (HELO sccrmhc12.comcast.net) (204.127.202.56) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Thu, 14 Jul 2005 01:10:15 +0000 Received: from [10.0.1.2] (c-24-61-199-96.hsd1.nh.comcast.net[24.61.199.96]) by comcast.net (sccrmhc12) with SMTP id <20050714010923012004c8sde>; Thu, 14 Jul 2005 01:09:23 +0000 User-Agent: Microsoft-Entourage/11.1.0.040913 Date: Thu, 14 Jul 2005 01:10:00 -0000 Subject: RE: Where does the C standard describe overflow of signed integers? From: Paul Schlie To: GCC Development Message-ID: Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-SW-Source: 2005-07/txt/msg00573.txt.bz2 > " ... A computation involving unsigned operands can never overflow, because > a result that cannot be represented by the resulting unsigned integer type > is reduced modulo the number that is one greater than the largest value that > can be represented by the resulting type." Although I don't intend to extend the debate; doesn't anyone find it curious that given this hard requirement, combined with the fact that all current machine architectures rely on 2's complement signed integer representation to eliminate the otherwise necessity for distinct signed integer arithmetic operations; that by extension unsigned and signed integer arithmetic operations are behaviorally equivalent all current machine implementations (as well as likely future implementations for the same reasons); therefore seemingly irrational and counter productive to presume otherwise, regardless of the standard's presently relatively ambiguous position on the subject for apparently largely historical reasons. As optimization seems to be a non-argument, as by analogy all optimizations which are available for unsigned arithmetic are correspondingly available for signed integer operations; as any signed value may then be thought of as being unsigned for the purposes of computation and/or comparison. i.e.: signed: 0 .. INT_MAX INT_MIN .. -1 0 ... unsigned: 0 .. UINT_MAX/2 .. UINT_MAX 0 ...