qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] QAPI and empty structs


From: Peter Maydell
Subject: [Qemu-devel] QAPI and empty structs
Date: Tue, 23 Dec 2014 15:50:35 +0000

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



reply via email to

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