All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] QAPI and empty structs
@ 2014-12-23 15:50 Peter Maydell
  2014-12-23 15:54 ` Eric Blake
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2014-12-23 15:50 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Markus Armbruster, Luiz Capitulino

In qapi-schema.json we have a couple of entries that define
empty structures, like this:

{ 'type': 'ChardevDummy', 'data': { } }

In the generated qapi-types.h these are turned into empty C structs:

struct ChardevDummy
{
};

and clang warns about them:
./qapi-types.h:3752:1: warning: empty struct has size 0 in C, size 1
in C++ [-Wextern-c-compat]
struct Abort
^
./qapi-types.h:3811:1: warning: empty struct has size 0 in C, size 1
in C++ [-Wextern-c-compat]
struct NetdevNoneOptions
^
./qapi-types.h:4282:1: warning: empty struct has size 0 in C, size 1
in C++ [-Wextern-c-compat]
struct ChardevDummy
^

Although you could argue that we don't care about differences
in C and C++ semantics, having a zero-sized struct floating
around seems a bit risky to me, since for instance a naive
attempt to g_malloc() space for it will return NULL.

How should we handle these? Should the qapi-types generator
stick a dummy field in so they aren't zero sized? Are they
actually an error in the schema? (what's the point of them?)
Do we claim that actually all our code correctly handles
zero sized structs and just suppress the clang warning?

thanks
-- PMM

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

end of thread, other threads:[~2015-01-12 15:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-23 15:50 [Qemu-devel] QAPI and empty structs Peter Maydell
2014-12-23 15:54 ` Eric Blake
2015-01-12 15:31   ` Markus Armbruster
2015-01-12 15:33     ` Peter Maydell

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.