From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10294 invoked by alias); 16 Aug 2004 18:58:09 -0000 Mailing-List: contact gdb-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sources.redhat.com Received: (qmail 10269 invoked from network); 16 Aug 2004 18:58:06 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 16 Aug 2004 18:58:06 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.10/8.12.10) with ESMTP id i7GIw6e1022418 for ; Mon, 16 Aug 2004 14:58:06 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id i7GIw6a10674 for ; Mon, 16 Aug 2004 14:58:06 -0400 Received: from localhost.localdomain (vpn50-19.rdu.redhat.com [172.16.50.19]) by pobox.corp.redhat.com (8.12.8/8.12.8) with ESMTP id i7GIw5EE008979 for ; Mon, 16 Aug 2004 14:58:06 -0400 Received: from saguaro (saguaro.lan [192.168.64.2]) by localhost.localdomain (8.12.11/8.12.10) with SMTP id i7GIw0Rs009346 for ; Mon, 16 Aug 2004 11:58:00 -0700 Date: Mon, 16 Aug 2004 18:58:00 -0000 From: Kevin Buettner To: gdb@sources.redhat.com Subject: Re: Preprocessor symbol style Message-Id: <20040816115800.5cc7d89f@saguaro> In-Reply-To: <200408132202.i7DM1x5k012167@elgar.kettenis.dyndns.org> References: <200408132202.i7DM1x5k012167@elgar.kettenis.dyndns.org> Organization: Red Hat Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SW-Source: 2004-08/txt/msg00219.txt.bz2 On Sat, 14 Aug 2004 00:02:00 +0200 (CEST) Mark Kettenis wrote: > IIRC this has been discussed before, hopefully people forgive me > raising the issue again. > > Currently in GDB we use the following style for preprocessor stuff: > > #ifdef HAVE_FOO_H > #include > #else > #ifdef HAVE_BAR_H > #include > #ifndef HAVE_FOOBAR > #define FOOBAR FOO(BAR) > #endif > #endif > #endif > > I think this style has a serious problem; it's rather difficult to see > how the #if's and #endif's balance. Personally I've been bitten by > this more than once. > > Many GNU projects (GCC, glibc, autoconf, coreutils) use a somewhat > different style: > > #ifdef HAVE_FOO_H > # include > #else > # ifdef HAVE_BAR_H > # include > # ifndef HAVE_FOOBAR > # define FOOBAR FOO(BAR) > # endif > # endif > #endif > > This makes it much easier to see how the #if's and #endif's balance. > > Can we please adopt the second style for GDB? We can convert things > incrementally, or if we want to do it all at once, I'll volunteer to > provide the mamoth patch. I agree that your proposed change is more readable than the current convention. I am in favor of this reindentation. But, since we've settled on ISO C, I think we can improve readability even more. How about this? #ifdef HAVE_FOO_H # include #elif defined(HAVE_BAR_H) # include # ifndef HAVE_FOOBAR # define FOOBAR FOO(BAR) # endif #endif One #ifdef / #endif pair has been removed by using #elif instead. There are cases where the use of #elif improves readability a lot more than is apparent from this example. Kevin