From: Kevin Buettner <kevinb@redhat.com>
To: gdb@sources.redhat.com
Subject: Re: Preprocessor symbol style
Date: Mon, 16 Aug 2004 18:58:00 -0000 [thread overview]
Message-ID: <20040816115800.5cc7d89f@saguaro> (raw)
In-Reply-To: <200408132202.i7DM1x5k012167@elgar.kettenis.dyndns.org>
On Sat, 14 Aug 2004 00:02:00 +0200 (CEST)
Mark Kettenis <kettenis@chello.nl> 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 <foo.h>
> #else
> #ifdef HAVE_BAR_H
> #include <bar.h>
> #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 <foo.h>
> #else
> # ifdef HAVE_BAR_H
> # include <bar.h>
> # 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 <foo.h>
#elif defined(HAVE_BAR_H)
# include <bar.h>
# 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
next prev parent reply other threads:[~2004-08-16 18:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-13 22:02 Mark Kettenis
2004-08-13 22:13 ` Daniel Jacobowitz
2004-08-14 10:40 ` Eli Zaretskii
2004-08-16 18:58 ` Kevin Buettner [this message]
2004-08-16 19:33 ` Michael Chastain
2004-08-24 20:25 ` Andrew Cagney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040816115800.5cc7d89f@saguaro \
--to=kevinb@redhat.com \
--cc=gdb@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox