From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15826 invoked by alias); 16 Feb 2011 23:22:59 -0000 Received: (qmail 15818 invoked by uid 22791); 16 Feb 2011 23:22:58 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-iw0-f175.google.com (HELO mail-iw0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Feb 2011 23:22:54 +0000 Received: by iwn8 with SMTP id 8so1887060iwn.20 for ; Wed, 16 Feb 2011 15:22:52 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.241.70 with SMTP id ld6mr1804156icb.124.1297898572547; Wed, 16 Feb 2011 15:22:52 -0800 (PST) Received: by 10.42.230.68 with HTTP; Wed, 16 Feb 2011 15:22:52 -0800 (PST) In-Reply-To: <4D5C576D.3060107@student.htw-berlin.de> References: <4D5C437F.5080207@cds1.net> <4D5C576D.3060107@student.htw-berlin.de> Date: Thu, 17 Feb 2011 06:31:00 -0000 Message-ID: Subject: Re: infinite for-loop and related question From: Jonathan Wakely To: Thomas Martitz Cc: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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/msg00249.txt.bz2 On 16 February 2011 23:02, Thomas Martitz wrote: > 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: >>>> >>>> =A0 for (char i(1); i>0; ++i) >>>> =A0 =A0 printf("%d %d\n", i, sizeof(i)); >>>> >>>> ... >>>> 362195 1 >>>> 362196 1 >>>> 362197 1 >>>> ... >>>> >>>> For very large values of char! =A0^_^ >>>> >>>> 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. > Well yeah, of course. But the value goes to zero and the loop terminates.