From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32206 invoked by alias); 21 Sep 2017 13:06:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 32196 invoked by uid 89); 21 Sep 2017 13:06:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=guidelines, sk:markus, nearer X-HELO: mga06.intel.com Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Sep 2017 13:06:18 +0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP; 21 Sep 2017 06:06:15 -0700 X-ExtLoop1: 1 Received: from irsmsx107.ger.corp.intel.com ([163.33.3.99]) by orsmga003.jf.intel.com with ESMTP; 21 Sep 2017 06:06:14 -0700 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.248]) by IRSMSX107.ger.corp.intel.com ([169.254.10.65]) with mapi id 14.03.0319.002; Thu, 21 Sep 2017 14:06:09 +0100 From: "Metzger, Markus T" To: Pedro Alves , Tom Tromey , "gdb-patches@sourceware.org" Subject: RE: [RFA 49/67] Constify some commands in btrace.c Date: Thu, 21 Sep 2017 13:06:00 -0000 Message-ID: References: <20170921051023.19023-1-tom@tromey.com> <20170921051023.19023-50-tom@tromey.com> <74f1184e-0d97-1082-4a51-3ae99c55717a@redhat.com> In-Reply-To: <74f1184e-0d97-1082-4a51-3ae99c55717a@redhat.com> dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-09/txt/msg00626.txt.bz2 > -----Original Message----- > From: Pedro Alves [mailto:palves@redhat.com] > Sent: Thursday, September 21, 2017 1:12 PM > To: Metzger, Markus T ; Tom Tromey > ; gdb-patches@sourceware.org > Subject: Re: [RFA 49/67] Constify some commands in btrace.c Hello Pedro, > >> @@ -3213,13 +3214,16 @@ get_context_size (char **arg) > >> if (!isdigit (*pos)) > >> error (_("Expected positive number, got: %s."), pos); > >> > >> - return strtol (pos, arg, 10); > >> + char *end; > >> + long result =3D strtol (pos, &end, 10); > >> + *arg =3D end; > >> + return result; > >> } > > > > The rest of the declarations are at the beginning. I'd prefer to keep = it that way. >=20 > Interesting. Out of curiosity, is there a particular reason for > that preference? I ask because we haven't adjusted our guidelines > in this area yet, but I've been asking people to move > declarations nearer where they're initialized in patch reviews. > My reasoning for that has been that IMHO, declarations nearer to > where they're initialized help with a few things: >=20 > - helps with reasoning about the code, since the type of > the variable has more changes of being visible. The > top of the scope may be a good number of lines above. >=20 > - helps prevent accidental used-uninitialized bugs. >=20 > - avoid gratuitous pessimization when the variable is of > non-trivial type, by avoiding separate default > construction + assignment steps. (though that's not the > case here, since in this case all variables are scalars). >=20 > The point that I feel particularly strongly about is the > last one, about non-trivial types, though as said that > doesn't apply in this case. >=20 > For the first two points, in C89, we'd some times open a > extra scope, like in this case you could write: >=20 > { > char *end; > long result =3D strtol (pos, &end, 10); >=20 > *arg =3D end; > return result; > } >=20 > In C99/C++, we can write declarations in the middle of > blocks without forcing the extra scope. My reason is simply to not mix different styles. > It's really up to you the style to use for this code as > btrace maintainer That shouldn't be the case. If GDB is moving from a separate declaration block to mixed-in declarations we should do it everywhere. So please ignore my comments on declaration placement. Regards, Markus. Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Christian Lamprechter Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928