From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28545 invoked by alias); 24 Apr 2012 22:11:06 -0000 Received: (qmail 28531 invoked by uid 22791); 24 Apr 2012 22:11:05 -0000 X-SWARE-Spam-Status: No, hits=-4.1 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,KHOP_THREADED,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 24 Apr 2012 22:10:52 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1SMnwi-0004ek-7u from Maciej_Rozycki@mentor.com ; Tue, 24 Apr 2012 15:10:52 -0700 Received: from SVR-IES-FEM-01.mgc.mentorg.com ([137.202.0.104]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 24 Apr 2012 15:10:51 -0700 Received: from [172.30.0.81] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.1.289.1; Tue, 24 Apr 2012 23:10:51 +0100 Date: Tue, 24 Apr 2012 22:11:00 -0000 From: "Maciej W. Rozycki" To: Tom Tromey CC: Sergio Durigan Junior , Jan Kratochvil , Subject: Re: Switch -Wunused-variable on? In-Reply-To: <87sjfufrlr.fsf@fleche.redhat.com> Message-ID: References: <20120422082240.GA21311@host2.jankratochvil.net> <87sjfufrlr.fsf@fleche.redhat.com> User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" 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 X-SW-Source: 2012-04/txt/msg00203.txt.bz2 On Mon, 23 Apr 2012, Tom Tromey wrote: > I'd say that the best approach would be to make the declarations > conditional in the same way that the uses are. > > If there are a lot of problem cases with this approach, or if it makes > the code too ugly, then maybe it would be better just not to use this > flag. That IMHO just asks to refrain from interspersing function bodies with preprocessor conditionals. Lots if not all conditional stuff can be factored out to headers or definitions elsewhere. Linux the kernel for one has had such a policy for years now. Example. Do not write this: int target_frobnicate (int count); #ifdef TARGET_NEEDS_HARD_FROBNICATION int target_frobnicate_harder (int count, int status); #endif int handle_frobnication (int count) { int status; int i; status = target_frobnicate (count); #ifdef TARGET_NEEDS_HARD_FROBNICATION for (i = 0; i < count; i++) status = target_frobnicate_harder (i, status); #endif return status; } Instead write this: int target_frobnicate (int count); #ifdef TARGET_NEEDS_HARD_FROBNICATION int target_frobnicate_harder (int count, int status); #define target_needs_hard_frobnication 1 #else #define target_needs_hard_frobnication 0 endif int handle_frobnication (int count) { int status; int i; status = target_frobnicate (count); if (target_needs_hard_frobnication) for (i = 0; i < count; i++) status = target_frobnicate_harder (i, status); return status; } -- "i" is now live in all cases and also IMHO handle_frobnication is more readable. Maciej