qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Why do we typedef every struct on QEMU?


From: Peter Maydell
Subject: Re: [Qemu-devel] Why do we typedef every struct on QEMU?
Date: Tue, 17 Jul 2018 21:06:31 +0100

On 17 July 2018 at 20:50, Eduardo Habkost <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]