From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8160 invoked by alias); 16 Feb 2011 23:02:15 -0000 Received: (qmail 8136 invoked by uid 22791); 16 Feb 2011 23:02:13 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail2.rz.htw-berlin.de (HELO mail2.rz.htw-berlin.de) (141.45.10.102) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Feb 2011 23:02:09 +0000 Envelope-to: gcc-help@gcc.gnu.org Received: from g231226084.adsl.alicedsl.de ([92.231.226.84] helo=[192.168.178.23]) by mail2.rz.htw-berlin.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72 (FreeBSD)) (envelope-from ) id 1PpqM3-000Pm4-7e for gcc-help@gcc.gnu.org; Thu, 17 Feb 2011 00:00:15 +0100 Message-ID: <4D5C576D.3060107@student.htw-berlin.de> Date: Wed, 16 Feb 2011 23:22:00 -0000 From: Thomas Martitz User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101208 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Re: infinite for-loop and related question References: <4D5C437F.5080207@cds1.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-HTW-SPAMINFO: this message was scanned by eXpurgate (http://www.eleven.de) X-HTW-DELIVERED-TO: gcc-help@gcc.gnu.org X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00248.txt.bz2 Am 16.02.2011 22:49, schrieb Jonathan Wakely: > On 16 February 2011 21:37, Bob Plantz wrote: >> On 02/16/2011 12:41 PM, Jason Mancini wrote: >>> Though I still find the output of this odd: >>> >>> for (char i(1); i>0; ++i) >>> printf("%d %d\n", i, sizeof(i)); >>> >>> ... >>> 362195 1 >>> 362196 1 >>> 362197 1 >>> ... >>> >>> For very large values of char! ^_^ >>> >>> Jason >> That's odd. With g++ 4.4.5 on an x86-64 machine in 64-bit mode I get: >> >> --- >> 125 1 >> 126 1 >> 127 1 >> >> which is what I would expect. That is, i is a (signed) char, and when it >> goes over 127 it becomes a negative number, so the loop terminates. > That would be the expected result if char was unsigned. Not exactly, no? An unsiged char goes to 255. Best regards.