Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <ac131313@ges.redhat.com>
To: David Carlton <carlton@math.stanford.edu>
Cc: gdb <gdb@sources.redhat.com>
Subject: Re: naive GDB programming style questions
Date: Mon, 09 Sep 2002 18:45:00 -0000	[thread overview]
Message-ID: <3D7D4ED2.2050401@ges.redhat.com> (raw)
In-Reply-To: <ro1u1kyah7d.fsf@jackfruit.Stanford.EDU>

> 1) It seems to me that some parts of GDB's source use NULL while other
>    parts use 0.  Is one or the other of these generally preferred?
> 
> 2) Am I correct in observing that GDB frowns on code like the
>    following:
> 
>      char *p = calculate_p ();
> 
>      if (!p)
>        p_is_zero ();

I'll assume that you ment ``p_is_null()''.

>    preferring this instead?
> 
>      char *p = calculate_p ();
> 
>      if (p == NULL)
>        p_is_zero ();
> 
>    Does it matter that p in a pointer rather than an integer, or that
>    the code is testing for zeroness rather than nonzeroness?

If you've a copy of the ISO C and C++ manuals, have a look at what they 
have to say about ``NULL'' pointers.  It's weird.

Anyway, for GDB, ``p == NULL'' is recommended to make it clear that the 
pointer is being tested and not the underlying value.

> 3) Is it possible to get CC Mode to indent in the way that GDB seems
>    to prefer?  I'm having a hard time getting structs to be indented
>    as follows:
> 
>      struct foo
>        {
>          int mem;
>        };

Just use:

struct foo
{
   int mem;
};

which is what is output by gdb_indent.sh and emacs.  The strange 
indentation that you've encountered dates back to an earlier version of 
indent.

Must get around to sending the FSF coding standards group a patch that 
documents this (it was agreed to in principle some time ago).

>    without screwing up my preferred indentation when doing non-GDB
>    programming, namely
> 
>      struct foo {
>        int mem;
>      };
> 
>    Of course, I can write functions to toggle between the two; but
>    given that both styles seem to be able to coexist for enums, maybe
>    it's possible to get them to coexist for enums.  (I'm certainly no
>    CC Mode expert...)

Andrew



  reply	other threads:[~2002-09-10  1:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-09 16:14 David Carlton
2002-09-09 18:45 ` Andrew Cagney [this message]
2002-09-09 20:52   ` David Carlton
2002-09-10 11:39     ` David Carlton
2002-09-10 16:15       ` Andrew Cagney
2002-09-12 11:35     ` Andrew Cagney
2002-09-10  8:56 ` Tom Tromey

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=3D7D4ED2.2050401@ges.redhat.com \
    --to=ac131313@ges.redhat.com \
    --cc=carlton@math.stanford.edu \
    --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