Eric Blake <ebl...@redhat.com> writes: > On 12/23/2014 08:50 AM, Peter Maydell wrote: >> 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: >> > >> 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. > > Oh, good point.
Less of an issue than with malloc(), because NULL isn't both an error and a success value. >> How should we handle these? Should the qapi-types generator >> stick a dummy field in so they aren't zero sized? > > Sounds like the best plan to me. I wouldn't bother myself, but if somebody posted working patches, I wouldn't bother objecting to the idea, either. >> Are they >> actually an error in the schema? (what's the point of them?) > > No, they are valid - it is how you express a union between a branch that > needs no additional members compared to any other branch. Yes. >> Do we claim that actually all our code correctly handles >> zero sized structs and just suppress the clang warning? > > I'd be fine with adding a dummy member. The clang warning is for code meant to be compiled both as C and as C++, i.e. it's of no interest to us. Suppressing it sounds fine to me.