public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Remove CHECK_TYPEDEF, use check_typedef instead
Date: Tue, 07 Jul 2015 16:15:00 -0000	[thread overview]
Message-ID: <559BFB12.6050606@redhat.com> (raw)
In-Reply-To: <1436213157-21480-1-git-send-email-simon.marchi@ericsson.com>

On 07/06/2015 09:05 PM, Simon Marchi wrote:
> I think that the CHECK_TYPEDEF macro is not necessary, and even a bit
> annoying.  It makes unclear the fact that the "type" variables gets
> overwritten.  It has actually bitten me a few times.  I think the
> following, explicit form, is better.
> 
>   type = check_typedef (type);
> 

I don't have a strong opinion either.  Whatever's fine with others
is fine with me.

Playing devil's advocate, the CHECK_TYPEDEF macro has the advantage
that makes it clear that you want to peel away typedefs are don't
really care about the original type.

I'd argue that the real issue with the macro is that it takes the
type pointer argument "by non-const reference to pointer".

Another solution would be to make it a function/macro that
instead takes a pointer to a type pointer.  Something like:

 void
 CHECK_TYPEDEFS (struct type **type)
 {
   *type = check_typedef (*type);
 }

Then you'd write:

 > -	  CHECK_TYPEDEF (result);
 > +	  CHECK_TYPEDEF (&result);

Or even rename it while at it:

 void
 peel_typedefs (struct type **type)
 {
   *type = check_typedef (*type);
 }

And so you'd write:

 > -	  CHECK_TYPEDEF (result);
 > +	  peel_typedefs (&result);

Then the code ends up self documenting, and there's no way to
forget to assign the return of the function back to the
argument.

Thanks,
Pedro Alves

  parent reply	other threads:[~2015-07-07 16:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 20:06 Simon Marchi
2015-07-07 13:20 ` Joel Brobecker
2015-07-07 16:15 ` Pedro Alves [this message]
2015-07-07 20:15   ` Simon Marchi
2015-07-07 22:01     ` Pedro Alves
2015-07-11 13:19   ` Doug Evans
2015-07-11 18:32     ` Pedro Alves
2015-07-11 22:52       ` Doug Evans
2015-07-14  9:34         ` Pedro Alves
2015-07-14 20:42           ` Simon Marchi
2015-07-13 17:18     ` Simon Marchi

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=559BFB12.6050606@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@ericsson.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).