All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Eduardo Habkost <ehabkost@redhat.com>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] Why do we typedef every struct on QEMU?
Date: Tue, 17 Jul 2018 21:06:31 +0100	[thread overview]
Message-ID: <CAFEAcA-pPsvfn7ARu_pn0HH03rZh05fLP=wr+p=hx5douSf7vA@mail.gmail.com> (raw)
In-Reply-To: <20180717195028.GA6691@localhost.localdomain>

On 17 July 2018 at 20:50, Eduardo Habkost <ehabkost@redhat.com> wrote:
> I have been looking at patches that touch typedefs.h and
> wondering: why do we make typedefs.h necessary at all?  Why do we
> always add typedefs for every struct and union type in QEMU?
>
> Why do we prefer to write this:
>
> ----- qemu/typedefs.h:
> typedef struct SomeType SomeType;
> ----------------------
>
> ----- qemu/somecode.h:
> #include <qemu/typedefs.h>
>
> int some_function(SomeType *a);
> ----------------------
>
>
> ...instead of simply writing this:?
>
> ----- qemu/somecode.h:
> struct SomeType;
> int some_function(struct SomeType *a);
> ----------------------
>
> Is the maintenance burden of typedefs.h worth it?

Personally I don't like typing "struct " all the time
when I'm using the type...

Note also that most typedefed structs don't go in
typedefs.h -- the typedef is defined with the struct.
A quick rough count suggests less than 10% are in
typedefs.h. We only put in the ones where there's
a lot of code that wants to use pointers to them
as opaque types and isn't pulling in the header where
the full struct is defined.

Also, this is one of the few bits of QEMU coding style
where we're pretty consistent, so I'd rather not
let it open to more free variation.

thanks
-- PMM

  reply	other threads:[~2018-07-17 20:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-17 19:50 [Qemu-devel] Why do we typedef every struct on QEMU? Eduardo Habkost
2018-07-17 20:06 ` Peter Maydell [this message]
2018-07-19  6:42   ` Markus Armbruster
2018-07-19  8:18     ` Thomas Huth
2018-07-19  8:28     ` Paolo Bonzini
2018-07-27 13:03     ` Stefan Hajnoczi
2018-07-27 13:14       ` Daniel P. Berrangé
2018-07-27 13:16       ` Peter Maydell

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='CAFEAcA-pPsvfn7ARu_pn0HH03rZh05fLP=wr+p=hx5douSf7vA@mail.gmail.com' \
    --to=peter.maydell@linaro.org \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.