From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19520 invoked by alias); 17 Jul 2013 21:12:56 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 19494 invoked by uid 89); 17 Jul 2013 21:12:55 -0000 X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,RDNS_NONE,SPF_PASS autolearn=ham version=3.3.1 Received: from Unknown (HELO mail-ie0-f177.google.com) (209.85.223.177) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 17 Jul 2013 21:12:54 +0000 Received: by mail-ie0-f177.google.com with SMTP id aq17so5162044iec.22 for ; Wed, 17 Jul 2013 14:12:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:x-gm-message-state; bh=gO/+Hc1I8NkIskekj4rtFuc9Ocb/23V4zZnSAVtB0UY=; b=GWFeo2voPt7WLvU5Lskc6yjvD96QH2GwlS9wq4HG768huBjosGvzUkAxzlmueLvI10 wMvRWJm9JS7TDwnkyVRUXE5yexH6Ns8pgeA2Qiy9XU9XtYvL4DJ59bAUdgWilYSmMIIK MoexEgU1Cwumzo1YbJxoDffzOjkRx6ZBYy/9uHUbO4qMRlmcH6fR1UgJmbeaUW+3lYT5 aq4qCX9kA3W1+qYwADg4K0x3pR7ZNA7U6iK/sxoaSkWAosCCjG9hWiuUperZQPskkemA XZCKdwEd9y9Lesfbulcd+RIxy4fDZv4FbVoZRW9E0ccSSwi+nXXLK+AS93pUszFvmHdW zKuA== MIME-Version: 1.0 X-Received: by 10.50.29.9 with SMTP id f9mr11295237igh.11.1374095567556; Wed, 17 Jul 2013 14:12:47 -0700 (PDT) Received: by 10.64.62.67 with HTTP; Wed, 17 Jul 2013 14:12:47 -0700 (PDT) In-Reply-To: <201307172048.r6HKmZhD018958@glazunov.sibelius.xs4all.nl> References: <87wqoqi5yf.fsf@fleche.redhat.com> <201307162122.r6GLMlMx012078@glazunov.sibelius.xs4all.nl> <201307172048.r6HKmZhD018958@glazunov.sibelius.xs4all.nl> Date: Wed, 17 Jul 2013 21:12:00 -0000 Message-ID: Subject: Re: C99 From: Doug Evans To: Mark Kettenis Cc: Tom Tromey , gdb Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQlbHST/3rc/xkYJ1/S3cwvDYuv+sDgmO/FTGRIC1K609OBegXmJq8pV702PGGIkWywomtc+TTJiLhvchg51fTD70wDdvb3LvygtbIqwZLSuN1JxPhDOlrzRHVBiJtaN7sfF5Kl6UjEHaEAiSxQDONBFx4DjYxHNau6lFoisgeIJ+W3OsmJWtAtxNn6+ceQw7x5s4Zir X-SW-Source: 2013-07/txt/msg00060.txt.bz2 On Wed, Jul 17, 2013 at 1:48 PM, Mark Kettenis wrote: >> > However, a more important C99 "misfeature" that affects the coding >> > standard is the possibility to declare varaibles anywhere in the code. >> > We should not allow this, except for declaring loop variables in a >> > for() statement. >> >> Can you elaborate? > > Code like this: > > int > foobar(char *foo, int bar) > { > sprintf(foo, "%d", bar) > int j = strlen(foo); > return j; > } > > is bad if you're trained to look for variable declerations at the > start of a block. C90 doesn't allow this; C99 changed that. Most > hardcore C programmers consider this a bad decision by the standard > committe. Most people do accept the following though: > > int > foobar(int bar) > { > int sum = 0; > > for (int i = 0; i < bar; i++) > sum += i; > > > return sum; > } Yeah, except I'm not seeing why it's a problem. Why is it a bad decision? What class of bugs does it cause? I can see that it makes it easier to find all the locals, but I'm more for declaring/initializing them close to their use.