On 21/03/2018 15:21, Marc-André Lureau wrote: >>> Yeah, I tried a few of those approaches. Here the problem is that >>> QObject doesn't have base field. So you get a compile time error with >>> a QObject * as argument. >> >> So the compiler requires &(x)->base to resolve even when it is not on the >> branch that gets selected? > > Unfortunately, yes, all branches must compile apparently (I know)...
Ugh, and that's indeed true of _Generic too. These don't compile: struct s1 { int y; }; struct s2 { int z; }; #define f(x) _Generic(x, struct s1: (x).y, struct s2: (x).z) int f1(struct s1 *s) { return f(*s); } int f2(struct s2 *s) { return f(*s); } :( Then I guess Marc-André's realization is ugly but unavoidable. Paolo