public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Preprocessor symbol style
@ 2004-08-13 22:02 Mark Kettenis
  2004-08-13 22:13 ` Daniel Jacobowitz
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Mark Kettenis @ 2004-08-13 22:02 UTC (permalink / raw)
  To: gdb

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.

Mark

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Preprocessor symbol style
  2004-08-13 22:02 Preprocessor symbol style Mark Kettenis
@ 2004-08-13 22:13 ` Daniel Jacobowitz
  2004-08-14 10:40 ` Eli Zaretskii
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2004-08-13 22:13 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb

On Sat, Aug 14, 2004 at 12:02:00AM +0200, Mark Kettenis wrote:
> 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.

Full support.  I don't see a need to do it all at once, though I
wouldn't object.

-- 
Daniel Jacobowitz

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Preprocessor symbol style
  2004-08-13 22:02 Preprocessor symbol style Mark Kettenis
  2004-08-13 22:13 ` Daniel Jacobowitz
@ 2004-08-14 10:40 ` Eli Zaretskii
  2004-08-16 18:58 ` Kevin Buettner
  2004-08-24 20:25 ` Andrew Cagney
  3 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2004-08-14 10:40 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb

> Date: Sat, 14 Aug 2004 00:02:00 +0200 (CEST)
> From: Mark Kettenis <kettenis@chello.nl>
> 
> #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?

I agree that the second style is more readable.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Preprocessor symbol style
  2004-08-13 22:02 Preprocessor symbol style Mark Kettenis
  2004-08-13 22:13 ` Daniel Jacobowitz
  2004-08-14 10:40 ` Eli Zaretskii
@ 2004-08-16 18:58 ` Kevin Buettner
  2004-08-16 19:33   ` Michael Chastain
  2004-08-24 20:25 ` Andrew Cagney
  3 siblings, 1 reply; 6+ messages in thread
From: Kevin Buettner @ 2004-08-16 18:58 UTC (permalink / raw)
  To: gdb

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Preprocessor symbol style
  2004-08-16 18:58 ` Kevin Buettner
@ 2004-08-16 19:33   ` Michael Chastain
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Chastain @ 2004-08-16 19:33 UTC (permalink / raw)
  To: kevinb, gdb

These files, among others, already use #elif:

  bfd/bfdio.c	since gdb 6.1
  gdb/top.c	since gdb 5.2.1
  gdb/utils.c	since gdb 4.17

So #elif is standard, and we're already using it!
Safe as houses.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Preprocessor symbol style
  2004-08-13 22:02 Preprocessor symbol style Mark Kettenis
                   ` (2 preceding siblings ...)
  2004-08-16 18:58 ` Kevin Buettner
@ 2004-08-24 20:25 ` Andrew Cagney
  3 siblings, 0 replies; 6+ messages in thread
From: Andrew Cagney @ 2004-08-24 20:25 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: gdb

Brain dump ...

The original requirement was for:

	|#ifdef

i.e., hard against margin, no spaces, that was eventually clarified into:

	|#

i.e., `#' hard against margin.  The ARI checks the latter.

As for coding style, can gdb_indent.sh be used to maintain this?  I'm 
reluctant to see us try to impose such an indention requirement without 
backing it with a robust and automated way of fixing / updating any files.

Andrew

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-08-24 20:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-13 22:02 Preprocessor symbol style Mark Kettenis
2004-08-13 22:13 ` Daniel Jacobowitz
2004-08-14 10:40 ` Eli Zaretskii
2004-08-16 18:58 ` Kevin Buettner
2004-08-16 19:33   ` Michael Chastain
2004-08-24 20:25 ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).