On 21/03/2018 16:29, Eric Blake wrote:
>
> Not necessarily - can we use multiple layers of macros? (Untested)
>
> #define QOBJECT_0(x) x
> #define QOBJECT_1(x) ({ \
> QEMU_BUILD_BUG_ON(offsetof(typeof(*x), base)); \
> &(x)->base; })
> #define QOBJECT(x) QOBJECT_ ## QEMU_GENERIC(x, \
> (QObject *, 0),
> (const QObject *, 0),
> 1)(x)
>
> or with an additional layer of glue() if needed
>
> That is, reduce the QEMU_GENERIC expansion into something that generates
> only a single preprocessor token, where we then use to decide which
> OTHER macro to expand, so that we are only evaluating &(x)->base when we
> selected the derived types.
I don't think so. Macro expansion happens way earlier.
Paolo